$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>admin - Hiding by default specific post status on backend list?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far