In every post of my custom post type called "announcements"
I save the users' ID inside an array which resides in a meta_key called "post_is_read"
whenever a user reads an announcement.
Just to explain: "post_is_read" contains an array (1, 2, 5, 12, 86, 100) where every number represents a user ID.
I achieved this using this code: https://wordpress.stackexchange.com/a/344315/15801
I am now trying to create a template which will show the posts a user has not read with the following code:
$current_user = wp_get_current_user();
$up_an_query_args = array(
'post_type' => 'announcement',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DSC',
'meta_query' => array(
array(
'key' => 'post_is_read',
'value' => $current_user->ID,
'compare' => 'NOT IN',
)
),
);
I have read every related article/answer I've found both on and off wordpress stackexchange and no method worked for me. The most I could get it to work is using 'compare' => 'NOT LIKE'
but it messed up the posts being displayed for users having at least a common digit in their IDs (ex between 1, 10, 11... etc) which is something I understand why is happening.