Add the following to an mu-plugin (custom user role is so76666381
) (tested):
// Adjust admin queries to only show pages by current user if has custom role.
add_action( 'pre_get_posts', static function ( $query ) {
// Limit hiding pages only to admin queries.
if ( ! is_admin() ) {
return;
}
// Get post types from query.
$post_types = ( array ) $query->get( 'post_type', array() );
// If pages are not being queried, bail.
if ( ! in_array( 'page', $post_types ) ) {
return;
}
// Get user's current role(s).
$roles = wp_get_current_user()->roles;
// If user does not have custom role, bail.
if ( ! is_array( $roles ) || ! in_array( 'so76666381', $roles ) ) {
return;
}
// Limit results to those by current user with custom role.
$query->set( 'author', get_current_user_id() );
} );