How to display by default only published posts/pages in the admin area?

As it is, WordPress displays by default all the pages/posts in the pages/posts list in the admin area, no matter what their publishing status is.

I have a lot of drafts, but usually I’m much more interested in editing the published pages/posts, therefore getting only to display them requires another click and full reload.

Read More

Is there a way to set WordPress to initially display only published posts/pages, allowing you to click on “All” or “Draft” if you later want to?

Related posts

Leave a Reply

2 comments

  1. I’m not sure if there’s another way, but manipulating the global variable $submenu can make this work.

    The following is just a manual hack (I’m not aware of any hook) and may fail on non-standard submenus set ups. The regular Post post type has a unique address and the rest of types has another one, hence two foreachs.

    add_action( 'admin_menu', 'default_published_wpse_91299' );
    
    function default_published_wpse_91299() 
    {
        global $submenu;
    
        // POSTS
        foreach( $submenu['edit.php'] as $key => $value )
        {
            if( in_array( 'edit.php', $value ) )
            {
                $submenu['edit.php'][ $key ][2] = 'edit.php?post_status=publish&post_type=post';
            }
        }
    
        // OTHER POST TYPES
        $cpt = array( 'page', 'portfolio' ); // <--- remove or adapt the portfolio post type
        foreach( $cpt as $pt )
        {
            foreach( $submenu[ 'edit.php?post_type=' . $pt ] as $key => $value )
            {
                if( in_array( 'edit.php?post_type=' . $pt, $value ) )
                {
                    $submenu[ 'edit.php?post_type='.$pt ][ $key ][2] = 'edit.php?post_status=publish&post_type=' . $pt;
                }
            }   
        }
    }
    
  2. To display published pages by default on pages link, simply paste this code snippet in your functions.php. You can then visit “All” tab to see full list of pages.

    // change page link to display published pages only
    function wcs_change_admin_page_link() {
        global $submenu;
        $submenu['edit.php?post_type=page'][5][2] = 'edit.php?post_type=page&post_status=publish';
    }
    add_action( 'admin_menu', 'wcs_change_admin_page_link' );
    

    If you want to achieve the same for post link in admin dashboard then use following code snippet instead.

    // change post link to display published posts only
    function wcs_change_admin_post_link() {
        global $submenu;
        $submenu['edit.php'][5][2] = 'edit.php?post_status=publish';
    }
    add_action( 'admin_menu', 'wcs_change_admin_post_link' );
    

    Reference: http://www.wpcodesnippet.com/wordpress-admin/change-pages-link-display-published-pages/