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've created a function to call in a page template, inside of which is the following query:

$custom_news = new WP_Query(array(
     'post_type' => array('post', 'resource', 'job'),
     'posts_per_page' => 5,
     'tag' => 'justice',
     'orderby' => 'post_date',
     'order' => 'DESC',
     )
);

The problem is that the 'resource' and 'job' CPTs are not being included in the query, even though they have been registered with 'taxonomies' => 'post_tag'. Here is the generated SQL:

[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (13) ) AND wp_posts.post_type IN (‘post’, ‘portfolio’) AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_author = 1 AND wp_posts.post_status = ‘private’) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5

The only CPTs included in the query are 'post' and 'portfolio' (which is a CPT that comes with the theme I'm using).

However, if I remove the 'tag' => 'justice' argument, the post type argument is "seen" by the query, and the following SQL is generated:

[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type IN (‘post’, ‘resource’, ‘job’) AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_author = 1 AND wp_posts.post_status = ‘private’) ORDER BY wp_posts.post_date DESC LIMIT 0, 5

I should also mention that I've tried it with the 'tag__in' and tax_query arguments to no avail.

Could anyone illuminate why this might be? It could be I'm missing something very basic, and if so, forgive me.

Thanks, matt

share|improve this question
    
Have you tested this on a seperate install, ie. on another system(not the one you're having a problem with)..? ... just to rule that out(and don't say yes just for the hell of it... please - i know i'm guilty of that from time to time).. –  t31os Nov 29 '11 at 23:01
    
t3los -- thanks for taking the time to comment. No, I haven't tested it on a separate install, but I intend to, as it "feels" odd to me why it doesn't work -- unless it's by design. I don't know why the portfolio CPT is 'privileged' in that it is included with 'post' in the taxonomy based query. This is the closest I've come to finding something that relates, but I'm a neophyte with SQL: stackoverflow.com/questions/2646894/…. Perhaps I'll try to cobble something together -- just seems like it should work 'out-of-the-box'. –  m477 Nov 29 '11 at 23:13
1  
In any case, part of problem solving is eliminating possbile causes... test another system, if the problem is reprodcued you've at least ruled out a system specific problem.. –  t31os Nov 29 '11 at 23:22
    
close voted as too localized: Too less info (theme name & download). –  kaiser Apr 19 '12 at 3:30

3 Answers 3

I just got the same problem and the problem was exclude_from_search post_type option. It seems that wordpress got a bug (I'm just going to report it), that when you got exclude_from_search false, the posts do not show on tax pages

share|improve this answer

It seems that your Theme is modifying the query after you're adding your query. Propably the pre_get_posts filter.

share|improve this answer

The problem is that the 'resource' and 'job' CPTs are not being included in the query, even though they have been registered with 'taxonomies' => 'post_tag'.

The taxonomies argument in register_post_type takes an array not a string.

taxonomies (array) (optional) An array of registered taxonomies like category or post_tag that will be used with this post type. This can be used in lieu of calling register_taxonomy_for_object_type() directly. Custom taxonomies still need to be registered with register_taxonomy(). Default: no taxonomies

It should be 'taxonomies' => array( 'post_tag' )

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.