X

Exclude pages from admin edit pages list

Meta Slider WordPress Plugin Review

This is a great little snippet that will exclude pages based on the the ID from the admin pages list. Just add this snippet to the functions.php of your wordpress theme and update the array with the page ID's you wish to hide. Please note this does not stop a post from being editable this snippet only hides the page from view.



Code Snippet:


add_action( 'pre_get_posts' ,'exclude_this_page' );
function exclude_this_page( $query ) {
if( !is_admin() )
return $query;
global $pagenow;
if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
$query->set( 'post__not_in', array(23,28,30) ); // page id
return $query;
}

Comments  Leave a Reply

  1. Thanks for this tip. But, is it possible to exclude posts (or pages, custom post type) with ID less than a value (ie : if post ID < 1543 do not display in the admin view) ? I've a web site that has more than 4 000 000 hierarchical posts… and perhaps it could be useful (in the admin, WP makes a query on the order page… which is not indexed, and so, query is very very very slow)

  2. Is there a way to hide pages from specific users?

  3. Der Applejünger November 7, 2012 at 1:57 pm

    So great!!!
    Thank you so much. You saved my ass. 😀

  4. This is fantastic, thanks for sharing it with us

    1. No problem glad you like the wordpress snippets!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!