【问题标题】:Pass multiple arrays through query string to Wordpress search通过查询字符串将多个数组传递给 Wordpress 搜索
【发布时间】:2015-03-19 17:39:29
【问题描述】:

我正在向 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

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

【问题讨论】:

  • http_build_query()

标签: php arrays wordpress search query-string


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多