Can't find a solution how to query posts without some specific value of meta_field that have many values.
The situation is:
I'm adding user id's on posts when they perform some specific operation. Like this: add_post_meta($_POST['post_id'], 'users_touched_ids', $current_user->ID);
After that I have to display to user posts that wasn't "touched" by him. So I'm writing query like this:
[
'relation' => 'OR',
[
'key' => 'users_touched_ids',
'compare' => '!=',
'value' => $user_id
],
[
'key' => 'users_touched_ids',
'compare' => 'NOT EXISTS',
],
]
But it doesn't work. I'm getting all posts =(
You getting all posts, while you query posts where
users_touched_idsnot equals to$user_id. This means, you get all posts where the database fieldusers_touched_idsnot contains the$user_idvariable.in case, the Author is the same as the "touch" user, you can filter the query by author like this: