Pass multiple arrays through query string to WordPress search

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…

Read More
/?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?

Related posts

Leave a Reply

1 comment

  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"]