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 using the following WP_Query arguments array:

$args = array(  'post_type' => POST_TYPE,
                            'tax_query' => array(
                                'taxonomy' => TAX,
                                'field' => 'slug',
                                'terms' => TERM
                            ),
                            'posts_per_page' => 2
                        );

The problem is this query displays all the posts from POST_TYPE which have a TAX (any TAX) assigned to them but it's not limiting it to the TERM (particularly one term) taxonomy!
I just want the posts from the specific TERM taxonomy and nothing more!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You're one array short. The tax_query is an array of arrays.

$args = array(  'post_type' => POST_TYPE,
                'tax_query' => array( 
                     array (
                      'taxonomy' => TAX,
                      'field' => 'slug',
                      'terms' => TERM
                     ), 
                 ),
                'posts_per_page' => 2
             );

See http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/ for more.

share|improve this answer
    
Thanks Otto, I didn't know it MUST be an array of arrays. You helped me a lot here. –  Hamed Momeni Jun 8 '12 at 16:50
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.