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 working on a solution to filter a custom post type by multiple terms in multiple taxonomies.

Here is my code:

<?php $term = "peoria,adams"; ?>

<div id="primary" class="content-area">
    <div id="content" class="site-content" role="main">

        <?php $term = explode(',', $term); ?>

        <?php $term_count = count($term); 
        $array_term = $term[0];

            $i = 1;
            while ($i < $term_count) {
                $array_term = "'" . $array_term . "', '" . $term[$i] . "'";

        <?php echo $term = "array( ". $array_term . " )"; ?>

        <?php //echo $array_term; ?>

            $args = array(
                'post_type' => 'property',
                'tax_query' => array(
                    'relation' => 'OR',
                        'taxonomy' => 'Status',
                        'field' => 'slug',
                        'terms' => array( 'Locked' )
                        'taxonomy' => 'County',
                        'field' => 'slug',
                        'terms' =>  $term
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post();
                echo '<div class="entry-content">';
                echo get_the_post_thumbnail();
                echo '</div>';

I echo $term and it display what it should display but it does not work when I call it in 'terms' => $term it does not work but it will work if I replace it with array( 'peoria', 'adams' ) it works.

I have a suspicion I'm doing something stupid but I'm just missing it. Can someone give me a hand?

Thanks in advance!

share|improve this question
up vote 0 down vote accepted

It looks like the problem is here:

'terms' =>  $term

where in your case it's like:

'terms' =>  "array( 'peoria', 'adams' )"

but it should be like

'terms' =>  array( 'peoria', 'adams' )

By looking at your code snippet, you could try

'terms' =>  explode( ',', $term );

since explode will return the array you are looking for.

So you shouldn't construct the array as a string.

Check for example the PHP manual on arrays here and explode here.

share|improve this answer
Thanks! that seemed to work! – graphical_force Jul 22 '13 at 20:14

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.