Dashboard Based

Hide Page from Dashboard Based on User Id

 

You can do it using pre_get_posts filter.

The code will look something like this:

add_action( 'pre_get_posts', 'misha_filter_admin' );
function misha_filter_admin( $query ){
    if( !is_admin() ) // for admin dashboard only
        return;

    if( $query->get('post_type') !== 'page' ) // we do not want it to work for posts and any CPT (custom post types)
        return;

    if( get_current_user_id() == 2 ) { // if user ID is 2
        $query->set('post__in', array( 4, 5, 7 ) ); // allow pages with IDs 4, 5 and 7
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here