• 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

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You’ve done nothing obvious wrong. To track down the problem I suggest you hook the ‘terms_clauses’ filter and output the array dump in some manner for examination. There should be some clear SQL flaw if the query itself is the problem. What that flaw is will indicate how to proceed.

    If that part is OK, you’ll need to debug what’s happening in class-wp-terms-list-table.php. It’s OK to alter core code for forensic analysis, just restore it to original when you’re done. There will not be any errors here, but by examining what’s happening here should shed light on what the problem really is.

Viewing 1 replies (of 1 total)

The topic ‘Filter terms in admin by child_of’ is closed to new replies.