2016-10-18 242 views
0

我有一個自定義字段Field Name: "participants"Field Type: "User"Wordpress WP_Query「NOT IN」not working

我想在元查詢中使用「NOT IN」,但它不起作用。

$getUid = $_REQUEST['uid']; 
$args = [ 
    'post_type' => 'polls', 
    'post_status' => 'publish', 
    'meta_query' => [ 
     'relation' => 'AND', 
     [ 
      'key' => 'participants', 
      'value' => [$getUid], 
      'compare' => "NOT IN" 
     ] 
    ] 
]; 

$the_query = new WP_Query($args); 
return $the_query; 
+0

能不能細說值 'UID'] 「不工作?」錯誤輸出或預期與實際結果是有幫助的甚至是必不可少的。 – Jacob

回答

0

使用此代碼,並確保你在$ REQUEST

$getUid = $_REQUEST['uid']; 
    $meta_query_args = array(
     'relation' => 'AND', // Optional, defaults to "AND" 
     array(
      'post_type' => 'polls', 
     'post_status' => 'publish', 
      'key' => 'participants', 
       'value' => [$getUid], 
       'compare' => "NOT IN" 
     ) 
    ); 
    $meta_query = new WP_Meta_Query($meta_query_args); 
+0

我得到以下輸出 –

+0

WP_Meta_Query對象 ( [查詢] =>數組 ( [0] =>數組 ( [post_type] =>輪詢 [post_status] =>發佈 [鍵] =>參與者 [值] =>數組 ( [0] => 1 ) [比較] => NOT IN ) [關係] => OR ) [關係] => AN D [meta_table] => [meta_id_column] => [primary_table] => .. –

+0

在$ the_query = new WP_Query($ meta_query)中傳遞此輸出。 –