سؤال

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