通过查询字符串将多个数组传递给 Wordpress 搜索

Pass multiple arrays through query string to Wordpress search

我正在向 Wordpress 搜索表单添加一些自定义筛选,允许用户按不同的分类法进行筛选。传递单个数组时一切正常,如:

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

但是,当添加不同分类法的第二个数组时,如...

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

...搜索结果页面上有少数 PHP 个错误

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

是否有更好的方法通过查询字符串传递两个单独的数组而不触发这些错误?

解决方案是为所有过滤器使用一个多维数组。通过将上面的查询修改为...

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

...我能够单独检索搜索结果页面上的值并避免所有错误。

$_GET["filters"]["genres"]
$_GET["filters"]["keywords"]