I created a new taxonomy called ‘country’ and have two terms items inside it: ‘USA’ and ‘Canada’. How do I go about querying this info? I have a filter page with two checkboxes:
<input type="checkbox" name="usa" value="USA" /> USA
<input type="checkbox" name="canada" value="Canada" /> Canada
How do I make the query show multiple results in case I have both boxes checked? I tried an array, but it didn’t work.
<?php query_posts( array('country' => array($_POST['usa'], $_POST['canada'])) ); ?>
2 Answers
You’ll want to use the tax_query
argument for query_posts/WP_Query.
query_posts( array(
"tax_query" => array(
array(
"taxonomy" => "country",
"field" => "slug",
"terms" => array( "usa", "canada" )
)
)
) );
The tax_query
argument is an array, so you can query multiple taxonomies.