admin - Hiding by default specific post status on backend list?

admin2025-06-04  4

I created various custom post status options (like default ones: "published", "draft" and so on) and one of them is "project closed". I need to hide/exclude by default from post list in the backend the posts set under "project closed" post status.

is there a way to this? thank you so much!

I created various custom post status options (like default ones: "published", "draft" and so on) and one of them is "project closed". I need to hide/exclude by default from post list in the backend the posts set under "project closed" post status.

is there a way to this? thank you so much!

Share Improve this question edited Mar 18, 2015 at 10:02 Daniele Chianucci asked Mar 17, 2015 at 17:08 Daniele ChianucciDaniele Chianucci 92 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

It's not clear what you're looking for here, but you could try to use the posts_where filter:

/**
 * Remove posts, with a given status, on the edit.php (post) screen, 
 * when there's no post status filter selected.
 */

add_action( 'posts_where', function( $where, $q )
{
    if(    is_admin()
        && $q->is_main_query()
        && ! filter_input( INPUT_GET, 'post_status' )
        && ( $screen = get_current_screen() ) instanceof \WP_Screen
        && 'edit-post' === $screen->id
    )
    {
        global $wpdb;

        $status_to_exclude = 'project_close';   // Modify this to your needs!

        $where .= sprintf( 
            " AND {$wpdb->posts}.post_status NOT IN ( '%s' ) ", 
            $status_to_exclude 
        );

    }
    return $where;
}, 10, 2 );

where you have to modify the $status_to_exclude status. Here we target the edit.php screen for the post post type. We make sure the post_status GET filter is not set.

So when you click on the All Posts admin menu link in the backend, this filtering is activated.

Hopefully you can adjust this further to your needs.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749022612a315698.html

最新回复(0)