This is how I did it :
function if_restrict_categories($categories) {
global $current_user;
$a = get_cat_if_user($current_user->ID);
$onPostPage = (strpos($_SERVER['PHP_SELF'], 'edit-tags.php'));
if (is_admin() && $onPostPage && !current_user_can('level_10')) {
$size = count($categories);
for ($i = 0; $i < $size; $i++) {
if($categories[$i]->parent != $a && $categories[$i]->term_id != $a){
unset($categories[$i]);
}
}
}
return $categories;
}
add_filter('get_terms', 'if_restrict_categories');
And where get_cat_if_user()
is a custom function where I get the category I’ve assigned to my user.
Hopes it helps others.
Cheers.
Related Posts:
- Weird behaviour when adding terms/term_taxonomies programmatically
- Add a wordpress blog to my website having users
- Allow contributors to add categories, but not delete
- Force a user’s posts category
- Filtering *out* a taxonomy from the admin post list
- Admin: Navigation Menus do not show empty categories/taxonomies in the list’s search tab
- Show parent-child relationship for categories in the wordpress admin
- Hide categories from authors
- How to display non-hierarchical taxonomy as terms with checkboxes?
- How to Change the Categories Order in the Admin Dashboard?
- Control term order on a per-post basis
- How to remove categories filter from wordpress admin?
- Can a Child Category Have More than One Parent?
- Combine two taxonomies in a hierarchical tree
- Make parent categories not selectable
- Create terms when registering taxonomy?
- How to Set an Individual Homepage for Each User?
- Why adding Categories does not auto refresh in Backend while using my custom theme?
- How to Override default update_count_callback for category
- Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- wp_list_categories, Add class to all list items with children
- Getting WordPress custom taxonomy/category?
- Display empty taxonomy terms with get_terms()
- Return category slug / title from category ID
- Connecting WordPress gallery to custom categories (taxonomy)
- How to sort categories by id in wordpress admin
- How to get the number of child categories a specific parent category has?
- Get term by slug in Gutenberg
- How to get the depth of a category’s subcategories
- New categories are now going to 404s
- Best way to programmatically link to multiple categories (union/intersection) [closed]
- “Reversable” and “Re-useable” Subcategories (or other taxonomic structure)
- Get multidimensional array that reflects category hierarchy
- Want to hide some categories from the categories meta box in the post editor for the two specific user roles
- Allow users to post to a certain category
- Get all sub-categories of a parent category
- Can I use get_adjacent_post for specific categories?
- Taxonomy filter all children
- Search Posts / Pages with multiple options?
- How to get the id from the custom category?
- How to filter out Categories for specific post types on WordPress Admin?
- Making the category & tag Description textarea bigger
- How can i insert term in a specific language of Polylang?
- Displaying different in-page content to cliente/admin
- How to “group” (categorize) the Pages together?
- Is There a Difference Between Taxonomies and Categories?
- How can I edit the ‘Most Used’ tab in the categories meta-box to show another custom taxonomy?
- Custom taxonomy/category order
- category doesn’t showing up in admin
- WP admin broken. Not saving catgories or adding categories to menu
- Why don’t posts show up in my categories on the frontend?
- How many categories can WordPress handle before performance suffers?
- Targeting Parent Category Pages
- get_terms function not returning anything
- Include WooCommerce product to all child categories
- Notice: Trying to get property of non-object in : custom fields category
- WP REST API not retrieving all categories
- How to display a value inside a post with a specified category from a category custom field? [closed]
- Some categories missing on wp-admin/edit-tags.php?taxonomy=category
- Display posts of certain categories to specific user roles
- How to restrict category creation to admins only while allowing editors to still pick category
- Eliminate word from $term->name
- What Must to Display the “mysite.com/category” URL?
- Is there any way to check which wordpress categories was created by which user?
- Mutliple users editing single document in wordspress
- Style a category from category list
- How to schedule categories?
- How should I setup the “Users” area to hand over to a client?
- Plugin permissions for Editor role
- Copy post taxonomy?
- Get posts in a subcategory of a chosen parent
- How to get posts using category slug in ClassiPress?
- Combining these queries? (Same taxonomy term + same category as post)
- get_the_category – display only a single category for a post (not all categories)
- display category with background color
- Newly created user role not displaying on users screen
- Disable Category Taxonomy
- How to set the same base url for two different taxonomies?
- How to set acf color field as background color to product category
- How to target all woocommerce categories that don’t have any subcategories in them?
- Show the parent taxonomy by creating shortcode in woocommerce?
- Display the articles of a category by role
- Filtering posts in category by tag URL
- Post List by category and under custom taxonomy
- get taxonomy list in a page in the wordpress
- Number of categories slowing down the site
- Image Upload Custom Form Field for Category and Custom Taxonomy
- How to check a category checkbox using JavaScript
- How to echo Tags and Categories as plain text
- How can I add HTML classes for current taxonomy/term hierarchy into my pages to simplify styles?
- Display List of Categories Within a Custom Taxonomy
- Defined user role to access plugin’s pages
- get_adjacent_post_link excluded_terms ignored
- Taxonomy for custom post type not found
- Category base 404 – fix
- Why is my post categories not displaying?
- Problem importing categories and sub-categories
- Forbid certain users to access a specific page
- Order Categories by Character Count