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

EDIT:
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' ),
));

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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(
        array(
            'taxonomy' => 'tagbbt',
            'field'    => 'term_id',
            'terms'    => array(90,89),
        ),
    ),
);
$query = new WP_Query( $args );


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x