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 working with a custom post type and trying to get a query working that includes 2 genres (a custom taxonomy).

I have this, which works for a single genre (I don't want to display the widget currently being viewed in the list, the 'post__not_in' takes care of that).

$myposts = new WP_Query( 
    array( 
        'post_type' => 'widgets', 
        'post__not_in' => array($wp_query->post->ID),  
        'genre' => 'styleA' 
    ) 
);

But I'm having trouble when I try to make a list that includes 2 genres.

I've tried various versions of this:

$myposts = new WP_Query( 
    array( 
        'post_type' => 'widgets', 
        'post__not_in' => array($wp_query->post->ID),  
        'genre' => array('styleB', 'styleC') 
    ) 
);

Everything I've read in the Codex seems to use a syntax like this, anyone know where I'm going wrong?

Much appreciated.

share|improve this question
    
What is genre ? –  Wyck Apr 19 '12 at 6:44
    
Sorry, it's a custom taxonomy. –  Sandbox Wizard Apr 19 '12 at 6:56
add comment

1 Answer

up vote 1 down vote accepted

Something along these lines should work:

$myposts = new WP_Query( array(
    'post_type' => 'widgets', 
    'post__not_in' => array($wp_query->post->ID),
    'tax_query' => array(
        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => array( 'styleA', 'styleB' )
        )
    )
) );

I'm not sure if you need to add 'relation' => 'OR', after line 4, so try it with/without that (i.e. before the 'tax_query'... line).

share|improve this answer
    
I could have sworn I tried something like that, but this worked. It was missing the 'array (' just after 'WP_Query (' - so I've added that into your answer. –  Sandbox Wizard Apr 19 '12 at 14:51
    
Whoopsy! Glad you got it sorted :) –  dunc Apr 19 '12 at 15:12
add comment

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.