hide some categories

Hide Some Categories in Post Editor and Quick Edit

If you run a multi author blog or your website maintenance team has a lot of members, you probably want to exclude or hide some categories from them.

Suppose, you have “Editorial” category or “Selected Posts” category where only you decide which post to go, then you have to hide these categories from other editors or authors so that they can’t publish posts under these categories.

You may have already tried some plugins such as “Restrict Categories”, “Author category” etc. These plugins used to work but no more.

In this tutorial, I will show how you can exclude some categories from WordPress post editor and quick edit. But beware of this:

Note: This will hide these categories on all REST requests. If your theme uses REST requests to display categories on the front-end, this tutorial is not for you.

Paste following codes into your theme’s functions.php file:

// remove categories from post editor and quick edit
function hide_categories_for_specific_user( $exclusions, $args ){
if ( ((defined( 'REST_REQUEST' ) && REST_REQUEST) or $GLOBALS['pagenow'] === 'edit.php' ) && !current_user_can( 'manage_options' ) ) {
   $exclude_array = array("437","469"); //IDs OF YOUR TERMS
   $exterms = wp_parse_id_list( $exclude_array );
   foreach ( $exterms as $exterm ) {
           if ( empty($exclusions) )
                   $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
                   $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
   if ( !empty($exclusions) )
       $exclusions .= ')';
   return $exclusions;
add_filter( 'list_terms_exclusions', 'hide_categories_for_specific_user', 10, 2 );

Change “437”,”469″ to your categories id.

To get category id, hover over the category and see the link:

how to find category id

Comment below to let us know if it works for you or not.

Spread the love

A teacher by profession, a traveler by passion and a netizen by choice.

Morshed Alam

You use WordPress! Why don't we share our experience! It may be a tutorial, tips, tricks or about security, performance or WordPress news. Write Today

1 thought on “Hide Some Categories in Post Editor and Quick Edit”

Leave a Comment

Your email address will not be published. Required fields are marked *