category__in not working on custom post type

Can’t get my WP_Query loop to work, cannot figure out why category__in won’t work. Just want to pull certain categories FROM my custom post type

$args = array(
  'post_type' => 'bbt',
  'category__in' => array(90,89)

$loop = new WP_Query($args);

when I use echo $loop->found_posts; it does returns 0, BUT I have 2 posts in total from those categories

Here is how the category was assigned:

    $labels = array(
    'name' => _x( 'Big Boys Toys Categories', 'taxonomy general name' ),
    'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Types' ),
    'all_items' => __( 'All Tags' ),
    'parent_item' => __( 'Parent Tag' ),
    'parent_item_colon' => __( 'Parent Tag:' ),
    'edit_item' => __( 'Edit Tags' ),
    'update_item' => __( 'Update Tag' ),
    'add_new_item' => __( 'Add New Tag' ),
    'new_item_name' => __( 'New Tag Name' ),

// Register Custom Taxonomy
register_taxonomy('tagbbt',array('bbt'), array(
    'hierarchical' => true, // define whether to use a system like tags or categories
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'tag-bbt' ),

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

category__in will never work as you aren’t making use of the build in taxonomy category. You are actually making use of a custom taxonomy called tagbbt. Take a look at this post, I have explained what the differences are

For custom taxonomies, you need to make use of a tax_query

Here is an example

$args = array(
    'post_type' => 'bbt',
    'tax_query' => array(
            'taxonomy' => 'tagbbt',
            'field'    => 'term_id',
            'terms'    => array(90,89),
$query = new WP_Query( $args );

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply