我的表單將複選框中的內容發佈到基於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