3

I have posted a question on StackOverflow (sorry for the cross link) and while I'm striving to find a solution to this, I stumbled across this warning :

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

And doing a backtrace, I find it originates in query.php :

wp_includes/query.php, lines 1710...1712

if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
     $q[$t->query_var] = wp_basename( $q[$t->query_var] );
}

Now, I get this error because one of my URL param is an array of categories, where I'm trying to search and return all product (custom post type) that has one or more of the defined categories assigned.

Why is WordPress trying to call basename on an array of GET parameter is beyond me. Anyone care to explain this to me? Thanks!

1 Answer 1

3

I'm not sure exactly what's happening, but I can guess based on a few context clues. That particular function is parse_tax_query. It appears to be checking if the taxonomy is hierarchical, I assume it's expecting a string that could possibly be a parent/child path of terms, so it uses basename to get the actual term queried- the next line is $term = $q[$t->query_var];

2
  • And what's the solution? I am having the same 'issue' when creating new WP_Query. Commented Aug 22, 2013 at 6:08
  • So the correct syntax that works for me in WP 3.6 is 'category__in' => $category where $category is an array. Commented Aug 22, 2013 at 6:22

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.