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?
The solution was to utilize a single multidimensional array for all filters. By modifying the query above to…
… I was able to retrieve the values on the search results page individually and avoid all of the errors.