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'm not able to use array for the terms in the following query, only a single term:

    'facts' => 'information', //taxonomy:facts and term:information
    'post_type' => 'book',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    $my_query = null;
    $my_query = new WP_Query($args)

Is this normal behiavour? Is there any equivalent method for selecting posts with certain terms from custom taxonomy with custom post type?

share|improve this question

You're using a deprecated method of querying by taxonomy. Read the Codex and use tax_query:

    'post_type' => 'book',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1,
    'tax_query' => array(
            'taxonomy' => 'facts',
            'field' => 'slug',
            'terms' => 'information'

FYI, caller_get_posts is also deprecated.

share|improve this answer

I'm not sure if this is the correct method (as I was not getting the results I wanted by supplying the 'relation' parameter for the 'tax_query' one), but we have a scenario at my work, where the site uses a taxonomy called 'topics' as the main menu, so it needed to be handled separately from the rest of the taxonomies, which were being used as lower level filtering options (i.e. 'schools') along with filtering for 'post_type'. Here's my solution, following mrwweb's example.

What's important to note is that if the query variable for 'schools' was empty, I got no results for the entire query, when it should produce all results, as 'schools' is no longer being filtered. So, I just through that part of the query array into a conditional, and it worked as expected.

function uci_get_taxonomies() {
    $params = array();

    $topic = get_queried_object();
    $params[TAXONOMY_TOPICS] = $topic->slug;

    $contentTypes = get_query_var('post_type');
    $params['post_type'] = $contentTypes;

    $schools = get_query_var(TAXONOMY_SCHOOLS);
    if(!empty($schools)) {
        $params['tax_query'][] = array('taxonomy' => TAXONOMY_SCHOOLS, 'field' => 'slug', 'terms' => $schools);

    $query = new WP_Query($params);

    return $query;
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.