0

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?

1 Answer 1

2

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' )
    )
) );
2
  • 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
    Commented Feb 21, 2013 at 22:28
  • 1
    @supertrue it is good habit to read the codex first... ;) Commented Feb 21, 2013 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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