Search code examples
wordpresscustom-post-typetaxonomy

WP_query twice on a single taxonomy


I have a simple WP_query on a custom post and works fine:

$args = array(
  'post_type' => 'post-type',
  'showposts' => 2,
  'location' => 'london'
);

but I want it to query two locations so used an array:

$args = array(
  'post_type' => 'post-type',
  'showposts' => 2,
  'location' => array('london','paris')
);

but it only pulls in the last term. Is there another way that I should be doing this?


Solution

  • $args = array(
        'post_type' => 'post-type',
        'tax_query' => array(
            array(
                'taxonomy' => 'location',
                'field' => 'slug',
                'terms' => array('london','paris')
            )
        )
    );
    

    Try this