我的表单将复选框中的内容发布到基于ajax的Wordpress wp_query。该复选框用作显示帖子的过滤器。其中一个复选框的设置作者-ID是这样的:
<label>
<input type="checkbox" name="check_author[]" id="<?php echo $author['name']; ?>" value="<?php echo $author['id']; ?>" checked>
<span class="checkName"><?php echo $author['name']; ?></span>
</label>
的$_POST['check_author']
输出(在复选框选中视)以下:
Array ([0] => 2 [1] => 1)
这些ID是确实是正确的,并与作者相对应的。
接下来,我在我的查询中插入数组。
$filters = $_POST['check_location'] || $_POST['check_themes'] || $_POST['check_author'] ;
if(isset($filters))
//print_r($_POST['check_author']);
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'location',
'field' => 'slug',
'terms' => $_POST['check_location'],
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $_POST['check_themes'],
)
),
'author'=> $_POST['check_author'],
);
//print_r($args);
$query = new WP_Query($args);
但$_POST['check_location']
和$_POST['check_themes']
正在像一个魅力和正确过滤我的查询。
我似乎不能让作者部分工作。我究竟做错了什么?
谢谢!这确实在查询中创建了一个成功的过滤器。令人遗憾的是,这造成了一种“关系”=>“与”的情况。有没有一种方法来查询与此不排除不同的查询? – WIWIWWIISpitFire
答案是否定的......因为它不是内部关系而不是任何元查询内部,它是一个类似于帖子类型的参数。如果该解决方案适合您,您可以接受它;) – Alice