WordPress – hide all pages in admin except one

I got my self into a bit of a pickle where I have a custom user role “librarian” and I would like to hide all pages from admin except the “library” page, so the librarian be able to edit this one page, all other pages will not show.

I found this code here where I can hide certain pages for custom roles:

add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('21','22','23');
    }
} 

As answered here: https://wordpress.stackexchange.com/questions/13528/hide-a-page-in-the-admin-end-without-a-plugin

But considering my site has 50 pages I would rather reverse this solution and hide ALL the pages and make then make only page id 21 visible to the librarian.

Would it be possible?

Read more here: WordPress – hide all pages in admin except one

Leave a Reply

Your email address will not be published. Required fields are marked *