I'm having a strange problem:

I've build a category page and want to load up all related posts of a custom post type but won't give any results. I'm using the following code:

  query_posts( array( 'post_type' => 'blog', 'showposts' => 3, 'cat' => 9 ) );

When deleting the 'cat' it shows all posts of the custom post type.

Is anyone familiar with this problem?

2 Answers 2



Taxonomy category with a term with id 9 dosen't have a posts with post type blog.

Are you sure that you using native category taxonomy for CPT blogs posts?

function query_report($sql){
    echo '<hr>';
    return $sql;
add_filter('query', 'query_report');
remove_filter('query', 'query_report');
  • Thanks for your reply Code Monkey, I'm not sure.. how can I find out I'm using the regular category? This is in my CTP functions.php: 'taxonomies' => array( 'post_tag', 'category'),
    – rwzdoorn
    Nov 19, 2012 at 10:15
  • well if you sure (let think that its support) try to query taxonomy term by slug (in case of category its - category_name) query_posts( array( 'post_type' => 'blog', 'showposts' => 3, 'category_name' => 'slug') ); Nov 19, 2012 at 10:46
  • Thanks again Code Monkey, nothing appears after your code so it looks like it's not supported?
    – rwzdoorn
    Nov 19, 2012 at 10:59
  • Looks like posts from content type blogs dosen't have relation to category you specifing... or its overiten by some filter/action hook. did category apears at the backend as selected whan you editing one of that "blogs" posts? Nov 19, 2012 at 11:08
  • They are selected when I'm creating or editing the post. When viewing the posts of 'blog' and clicking a category they won't popup in the results. So some function is blocking this?
    – rwzdoorn
    Nov 19, 2012 at 11:52

Ok, this code was bugging in my function.php:

<?php function namespace_add_custom_types( $query ) { 'if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {`
$query->set( 'post_type', array(
 'post', 'nav_menu_item', 'apps'
  return $query;
} } add_filter( 'pre_get_posts', 'namespace_add_custom_types' ); ?>

Problem solved, thanks Code Monkey!

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.