WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'])) ); ?>
share|improve this question

migrated from stackoverflow.com Feb 22 '11 at 3:07

This question came from our site for professional and enthusiast programmers.

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

You'll want to use the tax_query argument for query_posts/WP_Query.

query_posts( array(
  "tax_query" => array(
      "taxonomy" => "country",
      "field" => "slug",
      "terms" => array( "usa", "canada" )
) );

The tax_query argument is an array, so you can query multiple taxonomies.

share|improve this answer

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. Iterate through custom post type by custom taxonomy type? (Ordering wordpress posts by category, or displaying custom post type by taxonomy term)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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