How to hide certain categories in wordpress dashboard?

I have two categories which I dont want to show to my site’s admin, I want them to be added automatically everytime a new post is creatd or updated. I have the code for it. But now i also want to hide those two categories.

This is not for front-end. This is for wodpress dashboard. I dont want that admin will see these two categries at all. But if we hide those still I will be to assign two categories into posts.

Read More

Any clues???

Related posts

Leave a Reply

4 comments

  1. Got an answer in the first version of this answer:

    /*
     * Hide Specified Categories (by ID) from Editors
     */
    
    add_action( 'admin_init', 'wpse_55202_do_terms_exclusion' );
    
    function wpse_55202_do_terms_exclusion() {
        if( current_user_can('editor') )
            add_filter( 'list_terms_exclusions', 'wpse_55202_list_terms_exclusions', 10, 2 );
    }
    
    function wpse_55202_list_terms_exclusions($exclusions,$args) {
        return $exclusions . " AND ( t.term_id <> 1 )  AND ( t.term_id <> 17 )"; 
    }
    
  2. I found a plugin just now: http://wordpress.org/extend/plugins/restrict-categories/ which allow me to control which category will be displayed to which user and their roles. The good thing about this plugin is you can restrict categories not to show in admin mode where most of the other plugins will show everything in admin but has restriction to other users and their roles. I wanted something where i can hide two categories not to show in admin. so complete hidden from any users including admin.

    This plugin does it.

    Though categories can be hidden you can assign a post to that category automatically, so everytime a new post is published it assigns automatically to those hidden categories.

    Nice one.

  3. Ok find the solution. thanks to @brasofilo.

    the code is as follows:

    add_action( ‘admin_init’, ‘wpse_55202_do_terms_exclusion’ );

    function wpse_55202_do_terms_exclusion() {
    if( current_user_can(‘administrator’) )
    add_filter( ‘list_terms_exclusions’, ‘wpse_55202_list_terms_exclusions’, 10, 2 ); }

    function wpse_55202_list_terms_exclusions($exclusions,$args) {
    return $exclusions . ” AND ( t.term_id <> 69 ) AND ( t.term_id <> 70 )”; }