Custom Field Filter by Role - Wordpress

71 views Asked by At

Created a custom field and selected Filter by role "Subscriber" and assigned the custom field to the post type. Now when I add new post and assigned the subscriber (ie: Test Post and assigned the subscriber "grade 1") after I click on the update again I changed the subscriber "grade 1" to "grade 2", after that when I viewed the page by login as grade 1 that particular post is viewed. This Happens only if I edit the post and change the subscriber again.

            $args_events = array(
            'post_type' => 'parents_login',
            'post_status' => 'publish',
            'paged' => $page_num,
            'posts_per_page' => CUSTOM_ROWS_PER_PAGE,
            'cat' => get_cat_id( single_cat_title("",false) ),
            'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key' => 'select_grade',
                    'value' => $current_user->ID,
                    'compare' => 'LIKE',
                ),
            ),
        );

Please guide me to solve this issue

1

There are 1 answers

0
Sindhu On

I tried using serialize

        $args_events = array(
            'post_type' => 'parents_login',
            'post_status' => 'publish',
            'posts_per_page' => CUSTOM_ROWS_PER_PAGE,
            'cat' => get_cat_id( single_cat_title("",false) ),
            'meta_query' => array(
                array(
                    'key' => 'select_grade',
                    'value' => serialize( strval( $current_user->ID ) ),
                    'compare' => 'LIKE'
                ),
            ),
        );

Thanks and it is working fine.