Exclude drafts in all() view of edit.php

The show_in_admin_all_list parameter in the register_post_status() function, determines if a given post status is included in the All post table view.

Probably the shortest version is:

add_action( 'init', function() use ( &$wp_post_statuses )
{
    $wp_post_statuses['draft']->show_in_admin_all_list = false;

}, 1 );

but let’s avoid modifying the globals directly like this and override the default draft status with:

add_action( 'init', function()
{
    register_post_status( 'draft',
        [
            'label'                     => _x( 'Draft', 'post status' ),
            'protected'                 => true,
            '_builtin'                  => true, 
            'label_count'               => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ),
            'show_in_admin_all_list'    => false, // <-- we override this setting
        ]
    );

}, 1 );

where we use the priority 1, since the default draft status is registered at priority 0.

To avoid repeating the default settings and support possible settings changes in the future, we could use the get_post_status_object() instead:

add_action( 'init', function()
{   
    $a = get_object_vars( get_post_status_object( 'draft' ) );
    $a['show_in_admin_all_list'] = false; // <-- we override this setting
    register_post_status( 'draft', $a );

}, 1 );

Leave a Comment