Support

Account

Home Forums General Issues Filtering posts via the multiple select user field issues.

Unread

Filtering posts via the multiple select user field issues.

  • BACKGROUND
    So I have created a feed which shows a number of posts. Users are able to add options to the post such as category and notes etc. When they do this I take the user ID and assign it to the user field.

    So posts have a record of who have viewed the post by storing the users ID and name within the user “user field”.

    GOAL
    Im trying to only show posts that DO NOT contain the current user ID within the User Field.

    ISSUE
    How ever because of data being serialize I think im having some issues retrieving the correct posts.

    CODE
    This is my code that iv got so far and it’s not working.

            $query = new WP_Query( array(
                'post_type' => 'cpt_demo',
                'post_status' => 'publish',
                'posts_per_page' => -1,
                'order' => 'DESC',
    
                'meta_query' => array(
                    'relation' => 'OR', 
                    array(
                        'key' => 'users_who_have_seen',
                        'value'   => ':' . $get_current_user_id . ';', 
                        'compare' => 'NOT IN'
                    ),
                    array(
                        'key' => 'users_who_have_seen',
                        'compare' => 'NOT EXISTS'
                    )
                )
            ));
    

    Any help with this would be greatly appreciated as im completely stuck on this one.

Viewing 1 post (of 1 total)

The topic ‘Filtering posts via the multiple select user field issues.’ is closed to new replies.