Home » Tutorial » Hide Some Categories in Post Editor and Quick Edit

Hide Some Categories in Post Editor and Quick Edit

hide some categories

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 the 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:

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.

Read more from Tutorial

Written by:

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

Have you written on ThoughtMight?Write Today

Leave a Comment

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