我有一个自定义字段Field Name: "participants"
与Field Type: "User"
。
我想在元查询中使用"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;
使用此代码并确保在$REQUEST['uid']中获得值
$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 );