2017-05-09 26 views
1

我的表單將複選框中的內容發佈到基於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']正在像一個魅力和正確過濾我的查詢。

我似乎不能讓作者部分工作。我究竟做錯了什麼?

回答

1

,而不是author爲重點,用author__in

+0

謝謝!這確實在查詢中創建了一個成功的過濾器。令人遺憾的是,這造成了一種「關係」=>「與」的情況。有沒有一種方法來查詢與此不排除不同的查詢? – WIWIWWIISpitFire

+0

答案是否定的......因爲它不是內部關係而不是任何元查詢內部,它是一個類似於帖子類型的參數。如果該解決方案適合您,您可以接受它;) – Alice

1

您是否嘗試過沒有'relation' => 'OR'...?原因,我不確定'operator' => 'IN'

+0

「操作」,我刪除,但筆者仍不能正常過濾。 – WIWIWWIISpitFire