skip to Main Content

On the post edit page I have a category selection box. I would like to filter the displayed categories. How can I do this in PHP? I’ve tried finding the source of this box in the wordpress-src directory, but haven’t had any luck. Can I hook into this and filter what’s displayed?

enter image description here

2

Answers


  1. There are plugins that you can use which already achieve this type of functionality.

    See Taxonomy Filter

    Login or Signup to reply.
  2. I found a similar question answered here on the WordPress Stack Exchange:
    https://wordpress.stackexchange.com/questions/99034/how-i-can-hide-some-category-from-author-admin-panel

    /*
     * Hide Specified Categories (by ID) from authors
     */
    
    add_action( 'admin_init', 'wpse_55202_do_terms_exclusion' );
    
    function wpse_55202_do_terms_exclusion() {
        //Where is the string 'author' you need to replace it with your users' role
        if( current_user_can('author') )
            add_filter( 'list_terms_exclusions', 'wpse_55202_list_terms_exclusions', 10, 2 );
    }
    
    function wpse_55202_list_terms_exclusions($exclusions,$args) {
        // edit 3 with your category's ID
        return $exclusions . " AND ( t.term_id <> 3 ) ";
    }
    

    Tweak the answer from there to filter out any tag IDs you want hidden, you can also filter for specific user roles or remove that piece.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search