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
- Question on using custom structures for categories
- Notice: Trying to get property of non-object in : custom fields category
- how i can hide some category from author admin panel?
- Display sibling categories on category page
- How to modify the output of wp_terms_checklist when used within the built-in category metabox on edit posts?
- 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
- Echo text using is_tag
- List just subcategory and products of active category page in Woocommerce
- Display posts of certain categories to specific user roles
- Allow admins to login as other users
- How to restrict category creation to admins only while allowing editors to still pick category
- Grandchild Term Things Grandfather Term is It’s Parent
- Eliminate word from $term->name
- What Must to Display the “mysite.com/category” URL?
- WP 4.7 in_category change?
- Get posts of a custom post type from category from taxonomy?
- Is there any way to check which wordpress categories was created by which user?
- Redirect admin 403 “Cheatin uh?” admin pages
- Mutliple users editing single document in wordspress
- Illegal string offset ‘taxonomy’ in
- Style a category from category list
- How to restrict the amount of categories/post tags/terms for a post type post
- Same menu for different taxonomies to reach different content
- Change categories count to include media attachments
- How to schedule categories?
- How to get selected taxonomy or category ID if using custom walker?
- Remove specific administrator’s capability
- Let user select their own category
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How should I setup the “Users” area to hand over to a client?
- Plugin permissions for Editor role
- Copy post taxonomy?
- How could I write a get_categories_by_year() function?
- Get posts in a subcategory of a chosen parent
- Setting selected term_id with wp_dropdown_categories?
- creating categories programmatically
- Natural sort / ordering wp_dropdown_categories
- How to get posts using category slug in ClassiPress?
- Best way to categorize/populate a magazine style layout
- Mass Update User Profile Checkbox Options
- Combining these queries? (Same taxonomy term + same category as post)
- sidebar troubles, taxonomy trouble
- Displaying posts of given category
- 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
- Category post count is not correct
- Disable Category Taxonomy
- WordPress Default Category and Custom Taxonomy Selected Attribute not Working After Searched in wp_dropdown_categories Array
- Automatically adding tags and categories into Post Excerpt for searching
- How can i add service category here? [duplicate]
- Show subChild categories
- How can i change sort category view starting from child then parent, not alphabetically
- WordPress 5.4 and higher: Filter posts by category 1 AND category 2 in API requests
- Allow Custom Role to edit a custom post type category
- How to set the same base url for two different taxonomies?
- Limit categories to hierarchal depth of 2
- 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
- WordPress Portofolio Conditional Templating – functions php
- Parent Category and Subcategory default text generated with category
- Get WooCommerce product category list in functions.php
- Post List by category and under custom taxonomy
- Bulk assign posts to a category using SQL (MySQL)
- get taxonomy list in a page in the wordpress
- Number of categories slowing down the site
- How can I restrict the categories users can post in, based on user roles?
- Image Upload Custom Form Field for Category and Custom Taxonomy
- outputting taxonomy hierarchy
- How to check a category checkbox using JavaScript
- Hide top admin panel for non admin and non editors
- Confused about category.php template – not working
- Filter custom taxonomy posts via AJAX
- Create duplicate category page with content variations
- Why use hierarchical taxonomies instead of many custom taxonomies?
- Renaming default category taxonomy?
- How get all media from a posts category by db?
- 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?
- Add new post only in assigned category
- How to Manage and link certain custom taxonomy?
- wp_category_checklist won’t show up for non-admin users
- Display List of Categories Within a Custom Taxonomy
- Different role for free and pro users in wordpress without using bbpress
- Defined user role to access plugin’s pages
- Display Taxonomies in loop with template args
- How to add a post with new Taxonomy without assigning to default category?