Hide Some Categories in Post Editor
-
Hello,
I run a multi author blog. I want authors not to be able to publish posts under some categories(Suppose ‘selected’, ‘editorial’). So I want to hide them in post editor.I tried this code:
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('manage_options')) { $exclusions = " {$exclusions} AND t.slug NOT IN ('selected','editorial')"; } return $exclusions; }
But it is not working. I used this code too:
function hide_categories_for_specific_user( $exclusions, $args ){ if (!current_user_can('manage_options') ) { // IDs of terms to be excluded $exclude_array = array("5","6"); // CHANGE THIS TO IDs OF YOUR TERMS // Generation of exclusion SQL code $exterms = wp_parse_id_list( $exclude_array ); foreach ( $exterms as $exterm ) { if ( empty($exclusions) ) $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; else $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; } // Closing bracket if ( !empty($exclusions) ) $exclusions .= ')'; // Return our SQL statement return $exclusions; } } // Finally hook up our filter add_filter( 'list_terms_exclusions', 'hide_categories_for_specific_user', 10, 2 );
It works in the post editor but it breaks category widget in the front-end for non-admin users.
I used several plugins for that. “Restrict Categories, Author category” etc. But no luck. I am currently hiding them using css :nth-of-type. But works for add new post but it breaks when authors edit their post.
Can anyone help me?
Viewing 14 replies - 1 through 14 (of 14 total)
Viewing 14 replies - 1 through 14 (of 14 total)
- The topic ‘Hide Some Categories in Post Editor’ is closed to new replies.