问题
Just as title says really;
How can i hide specific categories from specified User Roles in Wordpress on the Add New Post page? So that users of a specific role cannot see the hidden categories (therefore, not post in them either).
I used to do this via a plugin but they havnt been updated in years and i dont seem able to find a replacement. So any help would be appreciated.
Cheers
回答1:
Answer converted to comment.
Apply this code to your own and should work.
add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);
function yoursite_list_terms_exclusions( $exclusions, $args ) {
global $pagenow;
if (in_array($pagenow,array('post.php','post-new.php')) && !current_user_can('see_special_cats')) {
$exclusions = " {$exclusions} AND t.slug NOT IN ('slug-one','slug-two')";
}
return $exclusions;
}
see_special_cats => the level of user in WordPress admin (admin, author etc...)
More info about users levels in WordPress
来源:https://stackoverflow.com/questions/45405507/wordpress-hide-specific-categories-from-user-role-on-the-add-new-page