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!

1 Answer 1


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' ) ", 

    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.

  • mmh... so i'm supposed to change array (123) with the tag id, but i'm not sure what it is. I mean, there're some post status (like "published", "draft" and so on. one of them is "project closed") i have to put "project-closed" into it? Commented Mar 18, 2015 at 9:29
  • It's possible to get the tag ID from the tag slug. It's also possible to use the tag slug in the tax_query part of the main query. But I just used the static tag ID here for demonstration purpose. You can also find the tag ID by hand, for example in the url (i.e. the tag_ID part) when you edit the corresponding tag. @DanieleChianucci
    – birgire
    Commented Mar 18, 2015 at 9:36
  • hmm, so you want to filter by post_status and not by a given tag? I thought you meant the latter case, since you wrote: tagged as "project closed" @DanieleChianucci
    – birgire
    Commented Mar 18, 2015 at 9:37
  • yes! i meant to filter by post status, not by tag. i'm sorry i wrote badly. and sorry for my english. i just want to hide posts under a specific post status from the list! Commented Mar 18, 2015 at 9:40
  • I updated the answer. Please edit your question with this extra info. @DanieleChianucci
    – birgire
    Commented Mar 18, 2015 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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