WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found out this code and works ok for hide pages in admin page listing, but I need someway to do this to thousand pages:

add_action( 'pre_get_posts' ,'hide_pages_87ff65f5f' );

function hide_pages_87ff65f5f( $query ) {

    if( !is_admin() )
        return $query;

    global $currentpage;

  $pages = array('2389','2605','2640','2970','2626');

  if( 'edit.php' == $currentpage && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
    $query->set( 'post__not_in', $pages );

    return $query;

Because I migrated a large static site I want to hide several pages and posts types from this specific month and year, I tried query and get_posts but something is not working, or maybe is not possible here :S

Infact I need to hide the content on every context in admin panel such parent option box, but this is quite enough for now.

Thanks a lot for any help!

share|improve this question
up vote 2 down vote accepted

The code you posted doesn't work because there is no global $currentpage.

There are $current_screen and $pagenow.

add_action( 'pre_get_posts', 'wpse_63414_hide_pages' );

function wpse_63414_hide_pages( $query ) {

    if( !is_admin() )
        return $query;

    global $pagenow;   
    $pages = array('2','26');

        'edit.php' == $pagenow 
        && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) 
        $query->set( 'post__not_in', $pages );

    return $query;

And to hide the array of pages in the dropdown boxes these filters have to be used:

add_filter( 'page_attributes_dropdown_pages_args', 'wpse_63414_hide_dropdown_pages' );
add_filter( 'quick_edit_dropdown_pages_args', 'wpse_63414_hide_dropdown_pages' );

function wpse_63414_hide_dropdown_pages( $args )
    $args['exclude'] = '2,26';
    return $args;

The child of the excluded pages are not shown as well. Although I'm not sure if this is the expected behavior...

share|improve this answer
Thanks brasofilo! Works pretty will! – Diana Jan 3 '13 at 16:51
Please note: Even if you are hidding pages with this is still possible to edit then from frontent (admin toolbar, "edit" link etc), unless you prevent this too. If you edit a child page while hidding, the parent relationship will be lost. – Diana Jan 4 '13 at 20:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.