Pregunta

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?

¿Fue útil?

Solución

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

Try this

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top