Hide posts if user is added to it WP_query

I have this list of posts in wordpress. I’ve made a favorite function that when you mark something as favorite it gets added to the front of the line. The issue here is I run this 2 place. One top panel which shows my favorite posts that I’m attached to and then the second post that shows my favorized posts from other users. Top panel works just fine.. But the issue is that my profile cards are shown in the second panel where other users cards are shown:
https://gyazo.com/75cf45a0844cba1f9ca6818e059d8bf6

As you can see… I have a duplicate in the second panel. How do I get rid of it using WP_Query?

Users are inside a multiple user field with ACF Fields.

I’ve tried doing all kinds of stuff such as AND and ORs. I am mostly likely close to the solution, but I can’t seem to find the solution..

TOP Panel code:

$aProjectArgs = array(
‘post_type’ => ‘project’,
‘post_status’=> ‘publish’,
‘posts_per_page’=> -1,
‘orderby’ => ‘favorit_users’,
‘order’ => ‘DESC’,
‘meta_query’ => array(
‘relation’ => ‘OR’,
array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘project_users’,
‘value’ => get_current_user_id(),
‘compare’ => ‘=’
),
array(
‘key’ => ‘project_users’, // name of custom field
‘value’ => ‘”‘.get_current_user_id().'”‘,
‘compare’ => ‘LIKE’
),
),
array(
‘relation’ => ‘AND’,
array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘project_users’,
‘value’ => get_current_user_id(),
‘compare’ => ‘=’
),
array(
‘key’ => ‘project_users’, // name of custom field
‘value’ => ‘”‘.get_current_user_id().'”‘,
‘compare’ => ‘LIKE’
),
),
“favorit_users” => array(
‘key’ => ‘favorite_users’,
‘value’ => get_current_user_id(),
‘compare’ => ‘LIKE’
),
),
),
);
$aProjectQuery = new WP_Query($aProjectArgs);

Second panel (LOWER):

$allProjectArgs = array(
‘post_type’ => ‘project’,
‘post_status’=> ‘publish’,
‘posts_per_page’=> -1,
‘orderby’ => ‘favorit_users’,
‘order’ => ‘DESC’,
‘meta_query’ => array(
‘relation’ => ‘OR’,
array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘project_users’,
‘value’ => get_current_user_id(),
‘compare’ => ‘!=’
),
array(
‘key’ => ‘project_users’,
‘value’ => ‘”‘.get_current_user_id().'”‘,
‘compare’ => ‘NOT LIKE’
),
array(
‘key’ => ‘favorite_users’,
‘compare’ => ‘NOT EXISTS’
),
),
“favorit_users” => array(
‘key’ => ‘favorite_users’,
‘value’ => $iCurrentUserID,
‘compare’ => ‘LIKE’
),
),
);
$allProjectQuery = new WP_Query($allProjectArgs);

In the end the duplicate should be hidden in the second panel. Pretty much every card I am attached to should be hidden. Cards with my favorite (stars) should stay IF it is not related to my user.

Read more here:: Hide posts if user is added to it WP_query

Leave a Reply

Your email address will not be published. Required fields are marked *