Hi, I'm developing a site in which users are limited to edit posts and terms assigned to a certain custom taxonomy terms, like this:
Group taxonomy:
- Department 1
- Group 1.1
- Sub_term 1.1.1
- Sub_term 1.1.2
- Group 1.2
- Sub_term 1.2.1
- Sub_term 1.2.2
- Group 1.3
- Sub_term 1.3.1
- Sub_term 1.3.2
- Department 2
- Group 2.1
- Sub_term 2.1.1
- Sub_term 2.1.2
- Group 2.2
- Sub_term 2.2.1
- Sub_term 2.2.2
- Group 2.3
- Sub_term 2.3.1
- Sub_term 2.3.2
Second level terms (Group x.x terms) are assigned to users saving a user_meta value, so users can only view and edit posts in assigned terms or its children (with pre_get_posts action) and can only view and edit the assigned term or its children (with get_terms_args filter).
I've modified terms args like this:
add_filter( 'get_terms_args', 'icb_filter_get_terms_args', 10, 2 );
function icb_filter_get_terms_args( $args, $taxonomies ) {
if ( $taxonomies[0] == 'grupo_inv' ) {
$user_group = get_user_group(); // int val. Gets assigned term, stored in user_meta. Returns false if no assigned group
if (is_admin() && $user_group) {
$args['child_of'] = $user_group;
}
}
return $args;
}
It's almost working, but terms list table in admin is not populating at all (it's empty and it's not showing any "no items found" message), and terms count above table shows all terms count (20 in this case) instead term children count (2).
Nevertheless, terms dropdown for parent term selection and terms checklist in post edit screen are filtered properly.
Can't anybody help me?
Thanks in advance