Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
    
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
add comment

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

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

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.

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.