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.

In WP_Query, a comma-separated list of term slugs works fine:

$query = new WP_Query ( array(  
     'customtaxonomy' => 'term1,term2'
) );

...but an array of slugs causes a warning:

$query = new WP_Query ( array(  
     'customtaxonomy' => array( 'term1', 'term2' )
) );

Warning: urlencode() expects parameter 1 to be string, array given in /path/to/wp-includes/formatting.php on line 3253

Another WPSE post proposes that this could be WP looking for hierarchy in a hierarchical taxonomy, but I can't think of any way to make sense of this behaviour. Do you know why this is happening?

share|improve this question

1 Answer 1

If you read the codex page carefully, you will see that taxonomy parameter {tax} (in your case it is customtaxonomy) takes only string value. Furthermore such taxonomy parameter is deprecated from version 3.1. So in your case you have to pass tax_query array with terms array:

$query = new WP_Query ( array(  
    'tax_query' => array( 
        'terms' => array( 'term1', 'term2' )
    )
) );
share|improve this answer
    
Interesting, I didn't realize that the taxonomy parameter is deprecated. Tangentially, writing a query string that would be parsable into tax_query seems quite complicated, if possible at all. (For example, I use a post listing shortcode with a query parameter.) –  supertrue Feb 21 '13 at 22:28
1  
@supertrue it is good habit to read the codex first... ;) –  Eugene Manuilov Feb 21 '13 at 22:38

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.