0

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!

3

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.

|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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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