Exclude Category In WordPress Admin Area


function shailan_filter_terms( $exclusions, $args ){

        if($args["taxonomy"][0] != 'location_cats') { return $exclusions; }

        // IDs of terms to be excluded
        $exclude = "9"; // CHANGE THIS TO IDs OF YOUR TERMS

        // Generation of exclusion SQL code
        $exterms = wp_parse_id_list( $exclude );
        foreach ( $exterms as $exterm ) {
                if ( empty($exclusions) )
                        $exclusions = ' AND ( t.term_id != ' . intval($exterm) . ' ';
                else
                        $exclusions .= ' AND t.term_id != ' . intval($exterm) . ' ';
        }

        // Closing bracket
        if ( !empty($exclusions) )
            $exclusions .= ')';

        // Return our SQL statement
        return $exclusions;


}

// Finally hook up our filter
add_filter( 'list_terms_exclusions', 'shailan_filter_terms', '9', 10, 2 );


Comments