I am having trouble to query cpt for the current user if s/he is in the meta value array.
query args
$args = [
'post_type' => $cp::get_module_cpt(),
'posts_per_page' => - 1,
'meta_query' => [
'relation' => 'AND',
[
'key' => 'premium_module',
'value' => 0,
'compare' => '=',
],
[
'key' => 'permit_users',
'value' => get_current_user_id(),
'compare' => 'IN',
],
],
];
meta key
permit_users
meta value
if has value
Array
(
[0] => 29
[1] => 28
...
)
if has no value
return false or empty array. Depends if ever set the field before.
additionally,
I have tried setting compare to =
equal but that also didn't work. Probably since the value is in array.
Result Looking
The query should return all posts that have current user id in the permit_users
key.
Important:
Thepermit_users
is an optional, so if the field has not value (false) or empty array, the query should ignore it.