【发布时间】:2019-06-13 23:41:09
【问题描述】:
这是我正在制作的过滤器的第二页,在第一页上,用户可以选择复选框。复选框的值通过 URL 中的参数传递到第二页:
filter-result/?mytaxonomy=myterm&mytaxonomy=myotherterm
如何形成此数据的数组以在 (WP) 查询中使用?
我可以通过这样做来显示来自 URL 的数据:
if( isset( $_GET['mytaxonomy'] ) ){
foreach( $_GET['mytaxonomy'] as $term ){
echo $term . '<br>';
}
}
我还可以查询帖子(自定义帖子类型):
$query = new WP_Query( array(
'post_type' => 'mycustomposttype',
'tax_query' => array(
array(
'taxonomy' => 'mytaxonomy',
'field' => 'slug',
'terms' => array( 'myterm', 'myotherterm' ),
'operator' => 'AND',
),
),
) );
我想将数据从$_GET['mytaxonomy'] 传递到'terms' => array( *inside here* )。
当我使用print_r ($_GET['mytaxonomy']); 时,结果是Array ( [0] => myterm ),完全正确。我想我只需要将数组形成为'a', 'b' 即可在 WP 查询中工作。我怎样才能做到这一点?
【问题讨论】:
标签: php sql arrays wordpress url-parameters