2

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.

Any clues???

2

You need to create a custom taxonomy for your needs. You can hide it and it won't be visible. Read more about custom taxonomies:

  1. Custom Taxonomies
  2. register_taxonomy function
  3. Taking WordPress Custom Taxonomies to the Next Level
  • I found a plugin just now: 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 role and ofcourse all other roles. so complete hidden. this plugin does it. – Zakir Sajib Jun 15 '12 at 4:59
2

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 )"; 
}
  • I dont understand following line: AND ( t.term_id <> 1 ) AND ( t.term_id <> 17 )" whats <> ?? – Zakir Sajib Jun 15 '12 at 5:08
  • i love to use this code, but it seems its not working. i want to hide two categories from admin, not the editor. – Zakir Sajib Jun 15 '12 at 5:12
  • Yes your code is working, sorry for my last message. i did chnage to administrator from editor, thats it. good one. thanks, now i dont need to use plugin. if( current_user_can('administrator') ) – Zakir Sajib Jun 15 '12 at 5:15
0

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.

0

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 )"; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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