Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

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 ?

share|improve this question
    
sorry, found the solution. Just change to 'views_edit-movie' instead, ;) –  Eugene Jul 8 '11 at 9:59
    
Eugene, if you find the answer to your own question, please post an answer below so others can benefit as well. In the mean time, I've posted the answer below as well. –  EAMann Jul 8 '11 at 15:40

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
Thanks EAMann for explaining the details. I actually did post the solution in the comment below my question. Anyway, I'll make it clearer next time by post a new answer to my question, not just comment. –  Eugene Jul 9 '11 at 3:49

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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