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 have an issue with a WP_Query for a site I'm building which has me stumped.

This works as expected:

                            $package_args = array(
                                'post_type' => 'vamos-cpt-packages',
                                'tax_query' => array(
                                    'taxonomy' => 'vamos-holiday-types',
                                    'field' => 'slug',
                                    'terms' => 'activity-holidays'
                                )
                            );
                            $packages = new WP_Query($package_args);
                            var_dump($packages);

But when the terms are an array:

                            $package_args = array(
                                'post_type' => 'vamos-cpt-packages',
                                'tax_query' => array(
                                    'taxonomy' => 'vamos-holiday-types',
                                    'field' => 'slug',
                                    'terms' => array('activity-holidays')
                                )
                            );
                            $packages = new WP_Query($package_args);
                            var_dump($packages);

It doesn't! I get no posts returned. Can anyone explain this?

Cheers Kevin

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

When you're doing a tax_query or meta_query in a WP_Query, you always have to use an array( array() ); - just see the following example for an explanation and pay attention to the relation argument.

$packages = new WP_Query( array(
    'post_type' => 'vamos-cpt-packages',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'vamos-holiday-types',
            'field'    => 'slug',
            'terms'    => array( 'activity-holidays' )
        ),
        array(
            'taxonomy' => 'vamos-holiday-types',
            'field'    => 'id',
            'terms'    => array( 103, 115, 206 ),
            'operator' => 'NOT IN'
        )
    )
) );
share|improve this answer
1  
Yes, can see my mistake - doh! Thanks for your swift reply –  user33792 Jun 6 '13 at 9:46
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.