Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote -1 down vote accepted

Blockquote

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){
    var_dump($sql);
    echo '<hr>';
    return $sql;
}
add_filter('query', 'query_report');
query_posts($your_arguments);
remove_filter('query', 'query_report');
share|improve this answer
    
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 '12 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') ); –  Oleg Butuzov Nov 19 '12 at 10:46
    
Thanks again Code Monkey, nothing appears after your code so it looks like it's not supported? –  rwzdoorn Nov 19 '12 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? –  Oleg Butuzov Nov 19 '12 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 '12 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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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