1

I am adding some custom filtering to the Wordpress search form allowing the user to filter by different taxonomies. Everything works when a single array is passed, as in:

/?s=example&genres[]=term1&genres[]=term2

However, when a second array is added of a different taxonomy, as in...

/?s=example&genres[]=term1&genres[]=term2&keywords[]=term3&keywords[]=term4

...there are a handful of PHP errors on the search results page

Warning: strpos() expects parameter 1 to be string, array given in /nas/wp/www/staging/pbsi/wp-includes/query.php on line 1861

Warning: preg_split() expects parameter 2 to be string, array given in /nas/wp/www/staging/pbsi/wp-includes/query.php on line 1862

Warning: Invalid argument supplied for foreach() in /nas/wp/www/staging/pbsi/wp-includes/query.php on line 1863

Warning: strpos() expects parameter 1 to be string, array given in /nas/wp/www/staging/pbsi/wp-includes/query.php on line 1861

Warning: preg_split() expects parameter 2 to be string, array given in /nas/wp/www/staging/pbsi/wp-includes/query.php on line 1862

Warning: Invalid argument supplied for foreach() in /nas/wp/www/staging/pbsi/wp-includes/query.php on line 1863

Is there a better way of passing two separate arrays through a query string that would not trigger these errors?

1
  • http_build_query() Commented Jul 27, 2021 at 7:34

1 Answer 1

1

The solution was to utilize a single multidimensional array for all filters. By modifying the query above to...

/?s=example&filters[genres][]=term1&filters[genres][]=term2&filters[keywords][]=term3&filters[keywords][]=term4

... I was able to retrieve the values on the search results page individually and avoid all of the errors.

$_GET["filters"]["genres"]
$_GET["filters"]["keywords"]
Sign up to request clarification or add additional context in comments.

Comments

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.