2

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'])) ); ?>
1
  • There are good suggestions in the answers below but I am not sure you are going to get a solid solution unless you post more detail, and more code. – s_ha_dum Feb 24 '13 at 15:13
4

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.

0

You’ll have to clarify your query, but these might also be helpful:

the_terms Displays the terms of a custom taxonomy: http://codex.wordpress.org/Function_Reference/the_terms

get_terms Retrieve the terms in taxonomy or list of taxonomies: http://codex.wordpress.org/Function_Reference/get_terms

I just found this after days of searching for this solution which may also be what you’re after. https://stackoverflow.com/questions/3848608/iterate-through-custom-post-type-by-custom-taxonomy-type-ordering-wordpress-pos

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.