I am trying to get all custom type posts from specific taxonomy. Here is my code:

$product_wood = get_posts(array(
'post_type' => 'product_document',
'post_status' => array('publish'),
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
'tax_query' => array(array(
    'taxonomy' => 'cadassist_category',
    'field' => 'id',
    'terms' => array( 653 ) // wood frame
'cache_results' => false,
'update_post_meta_cache' => false,
'update_post_term_cache' => false));

And this piece of code behaves in a strange way. For some taxonomies it retrieves posts for others it doesn't. For example for taxonomy with ID 653 it retrieves nothing (an empty array), while for taxonomy with ID 408 it works perfectly!

All taxonomies have posts associated with them. But some work and the others doesn't! I've tried to use slug instead of id. The result is the same.

Please help to solve this issue and/or show why it behaves in this way?

1 Answer 1


After several hours of debugging I have found what caused the problem. Custom taxonomy 'cadassist_category' is used for 2 custom post types: product_document and cadassist_file. The posts for taxanomy with ID 653 were of cadassis_file type. And I tried to get posts of product_document type. That is why I got empty array.

So if you have similar problem then maybe your custom taxonomy is used for several post types and you just query for a wrong post type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.