#StackBounty: #custom-post-types #custom-taxonomy #wp-get-object-terms wp_get_object_terms(): count relative to passed IDs?

Bounty: 50

I know when you wp_get_object_terms() you get a “count” member variable for each term object returned, but that “count” is what’s in the $wpdb->term_taxonomy table in the database, it’s not relative to the IDs you pass in as the first parameter. How do I get that number, though?

Example, something like:

$query = new WP_Query(array('post_type' => 'foo', 'numberposts' => 20));
$ids = wp_list_pluck($query->posts, 'ID');
$terms = wp_get_object_terms($ids, 'multi_post_type_tax');

So I want the count returned to be relevant to the query, meaning the count I get is only for the passed in post IDs. Each term object returned from the tax “multi_post_type_tax” may have a count of 400 because it applies to other post types that aren’t in my query, but since I passed in specific IDs, I want that count to apply to that query, meaning a count > 20 wouldn’t make any sense at all (and most likely for a particular term, it’d be less than 20, I can’t see every post in a post type having the same term usually). It seems like that would work but the returned value from wp_get_object_terms has unique objects.


Get this bounty!!!

#StackBounty: #custom-post-types #ajax #pagination How to load custom post archives sub-pages with ajax?

Bounty: 50

I’d like to keep the pagination links for /page/2/, /page/373/, etc but instead of changing the URL on the browser i want everything to load on the archive main page.

Ideally all those paginated URLs should redirect to the first page of the archive.

I don’t want a “load more” button i want to keep the logic of pages but load them via ajax keeping url unchanged.

How can i do this? Any help is appreciated.


Get this bounty!!!

#StackBounty: #custom-post-types #wp-query #categories WP_Query with custom post_type and cat retrieving unwanted posts with the custom…

Bounty: 50

I have a custom post type “projets” that is using the category taxonomy (so it is sharing categories with regular posts).

When I call WP_Query like this:

$args = array(
    'post_type' => 'projets',
    'posts_per_page' => 6,
    'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1,
);
$projects = new WP_Query($args);

It works perfectly fine.
But when I add a category to the arguments like this:

$args = array(
    'post_type' => 'projets',
    'posts_per_page' => 6,
    'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1,
    'cat' => 39
);
$projects = new WP_Query($args);

It does not returns only projets custom post_type but also regular posts that share the category 39…
Is there a way to make sure only the custom post type will be returned?

For info I use the Custom Post Type UI extension to declare the post type, I did not declare them myself.


Get this bounty!!!