admin管理员组

文章数量:1122832

As the title says, I want to hide certain categories from certain user roles when they go to make a new post. I have tried all the codes I could find out there including this, this, this and this. The plugins that have been suggested are now removed from Wordpress and none of the code works. Either they hide ALL categories or hide no categories. I've tried adding the name of the user role in the respective fields of the role I want to prevent from seeing the category as well as the name of the only role I would like to allow (ie administrator) as well as their role ID and nothing works.

Are there any up to date solutions out there?

Edit:
I tested it some more and discovered that link 4 works (even though I purged and cleared the cache, I still had to refresh the post page 3 times for the settings to show) but it also hides the category on the front end too so they cannot even see the category eg if they go to sitedomain/category/hidden-category, it returns a 404 for them.

I only want to prevent people from posting in specific categories, not prevent them from seeing it.

As the title says, I want to hide certain categories from certain user roles when they go to make a new post. I have tried all the codes I could find out there including this, this, this and this. The plugins that have been suggested are now removed from Wordpress and none of the code works. Either they hide ALL categories or hide no categories. I've tried adding the name of the user role in the respective fields of the role I want to prevent from seeing the category as well as the name of the only role I would like to allow (ie administrator) as well as their role ID and nothing works.

Are there any up to date solutions out there?

Edit:
I tested it some more and discovered that link 4 works (even though I purged and cleared the cache, I still had to refresh the post page 3 times for the settings to show) but it also hides the category on the front end too so they cannot even see the category eg if they go to sitedomain.com/category/hidden-category, it returns a 404 for them.

I only want to prevent people from posting in specific categories, not prevent them from seeing it.

Share Improve this question edited Aug 1, 2024 at 4:25 I have many questions asked Aug 1, 2024 at 2:50 I have many questionsI have many questions 1717 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

Working solution for Wordpress 6.6.1 Aug 2024:
I am going to answer my own question since I found an answer now, in case it is useful for others.

As of Aug 2024, there are no plugins that can do this and the plugins mentioned in several guides on the internet have been removed. I have found a code solution that works on 2024 fo Wordpress 6.6.1:

The code posted in the accepted answer here by Khadka Pushpendra still works for Aug 2024. It is very similar to the 4th link in my original question, but I tested it and unlike the code in link 4, this one does not hide the category in the front end, only in the back end on the Add Post page which is exactly what I want. It hides certain categories from all user roles other than Administrators (see below).

Where it says "current_user_can( 'manage_options'", if you need to, change the "manage_options" to a capability that only administrators have. Then everyone who does not have this capability will not see the categories. eg for me, I have other users with the "manage_options" capability so I couldn't use this, I had to change it to "create_users" because only admins can do that.

It might give them the ability to edit categories (ie change the spelling or even delete categories) but if you remove this abilty, they will not be able to add new ones either, so I used an admin dashboard menu editor such as Advanced Access Manager to remove access to the Post -> "Categories" option, so the non-admin users can only add new categories but not edit existing ones.

Hope this is helpful to someone.

本文标签: How to hide specific categories in the quotadd postquot section for specific user roles