How to Hide Certain Pages from Editor (WP Dashboard)

How to Hide Certain Pages from Certain Users (WP Dashboard)

How to Hide Certain Pages from Editor (WP Dashboard)

There are instances wherein there is a need to hide some pages from certain users because we don’t want them to edit those pages.

Code snippet:

add_filter( 'pre_get_posts', 'removePageFromDashboard' );

function removePageFromDashboard($query) {
  $user = wp_get_current_user();
  if (is_admin() && in_array( 'editor', (array) $user->roles )) {
    $hide_pages = array(postid1, postid2);
    $query->set('post__not_in', $hide_pages);
    return $query;
  }

} //function