Remove All, Published and Trashed Post Views in Custom Post Type

I want to remove the below text links in Edit Post screen:

All (8) | Published (5) | Draft (1) | Pending (2) | Trash (2)

Read More

After searching, i found that this can be done by this code here, but sadly it only works with ‘post’ type. I’m failed to make it works with my custom post type:

add_action( 'views_edit-post', 'remove_edit_post_views' );
function remove_edit_post_views( $views ) {
        if( get_post_type() === 'movie' )  {
            unset($views['all']);
            unset($views['publish']);
            unset($views['trash']);
        }

        return $views;
}

What’s wrong with my code ?

Related posts

Leave a Reply

2 comments

  1. Further down on the page you linked to is this comment:

    Similar views can be edited by hooking into ‘views_’ . $screen->id where $screen is the global $current_screen (or get_current_screen()). Draft, Pending, Mine and Sticky could all be removed in a similar manner.

    When you’re editing a post, you’re on the “edit-post” screen, so the action you use is views_edit-post. If you’re working with a custom post type called “gallery,” the edit screen is “edit-gallery” and you’d hook into the views_edit-gallery action.

    In your case I’d do the following:

    function remove__views( $views ) {
        unset($views['all']);
        unset($views['publish']);
        unset($views['trash']);
    
        return $views;
    }
    
    add_action( 'views_edit-post',  'remove_views' );
    add_action( 'views_edit-movie', 'remove_views' );
    

    This will remove “all”, “publish”, and “trash” from both posts and the custom post type “movie.” Removing these views from other post types is as simple as adding the following line:

    add_ection( 'views_edit-{post-type-slug}', 'remove_views' );
    

    Just replace {post-type-slug} with the name of your custom post type.

  2. I was doing something similar and grabbed this code and realized that “Draft” still showed up, so some testing shows you can just do one line:

    unset($views);
    

    This will remove all of them if your goal is to remove the whole line. I’m on WP 3.5 FWIW.