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?

有帮助吗?

解决方案

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

Try this

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top