• Resolved Ale12

    (@ale12)


    Hello,

    Hope you are well.

    I would like to filter the value that populate in Taxonomy admin panel by users.
    Here are some questions.

    1. Are there any action, hook, filter can use to do this?
    2. If there is no action nor other things available, where can I change value that populate data in taxonomy like category manage panel?

    3. I saw a post that might fit to what I need but not sure what file I can apply the code in URL below to ?

    Here is the link: https://wordpress.stackexchange.com/questions/8428/multiple-users-only-allow-them-to-manage-their-own-terms-for-custom-taxonomy-w

    I researched the ‘list_terms_exclusions’ but could not find in WordPress Codex about its details. Maybe I’m wrong. If you see the codex explanation for ‘list_terms_exclusions’ could you please reply with link to this post here. Your help is greatly appreciated.

    Thanks very much for your time and consideration.

    -Ale12

Viewing 1 replies (of 1 total)
  • Thread Starter Ale12

    (@ale12)

    I found the answer from this link below
    https://wordpress.stackexchange.com/questions/30911/excluding-categories-from-manage-categories-using-a-get-terms-filter

    The category and taxonomy are interchangeable. It both use same function call get_terms.

    To filter taxonomy you will use same filter call ‘get_term_args’
    But in your function you would need to omit the section in the if clause ” ‘category’!==$taxonomies[0]”

    For example, if you want to exclude the taxonomy id 10,12

    you can do this way

    add_filter( 'get_terms_args', 'mamaduka_edit_get_terms_args', 10, 2 );
    /**
     * Exclude categories from "Edit Categories" screen
     *
     */
     function mamaduka_edit_get_terms_args( $args, $taxonomies ) {
    
        $args['exclude'] = array( 10, 12); // Array of cat ids you want to exclude
        return $args;
    }

    put this code into your theme functions.php file. This will exclude taxonomy term_id 10, 12 from all users.

    Then, if you want to excluded term by user capability you can do something like this

    add_filter( 'get_terms_args', 'mamaduka_edit_get_terms_args', 10, 2 );
    /**
     * Exclude taxonomy from "Edit taxonomy" screen
     *
     */
     function mamaduka_edit_get_terms_args( $args, $taxonomies ) {
        if ( current_user_can('manage_movie') )
            return $args;
    
        $args['exclude'] = array( 10, 12); // Array of cat ids you want to exclude
        return $args;
    }

    // in the If () assume that you have ‘movie’ as your taxonomy and the only user who have capability to ‘manage_movie’ is admin. This way it’s allow only administrator to see all movie taxonomy ‘terms

    And any users for example, author who doesn’t have ‘manage_movie’ capability will have term (movie) id 10,12 excluded from his/her
    manage movie panel ( taxonomy admin panel)

    You can use same method to filter/exclude category value from Edit Categories too.

    Explanation about taxonomy and capability see Justin Tadlock link : https://justintadlock.com/archives/2010/06/10/a-refresher-on-custom-taxonomies

    Hope it helps
    -Ale12

Viewing 1 replies (of 1 total)
  • The topic ‘How to Filter value that populate in Taxonomy Admin Panel?’ is closed to new replies.