Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using a filter on get_terms (see below) to remove a specified number of named categories from the "Manage Categories" listing. It works great, however, the excluded categories are still counted in the category count field that's displayed just under the "Search Categories" button.

Is it possible that I can subtract these categories from the count?

function admin_edit_tags() {add_filter( 'get_terms', 'admin_trim_category_description', 10, 2 );}

function admin_trim_category_description( $terms, $taxonomies ){
    if( 'category' != $taxonomies[0] )return $terms;
    $my_categories = array('test1','test2','test3');
    foreach( $terms as $key => $term) 
        if(in_array($terms[$key]->name, $my_categories)) { unset($terms[$key]);}
        else
        {
        if(isset($terms[$key]->description) && $terms[$key]->description !=='') $terms[$key]->description = strip_tags(substr( $term->description, 0, 75 ))."...";
        }
        return $terms;
    }
share|improve this question

1 Answer 1

up vote 2 down vote accepted

I think you should use get_terms_args filter instead of get_terms and just add exclude arg, so now get_terms() function won't retrieve those cats and you'll get right count. Here's code example:

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 ) {
    if ( is_admin() && 'category' !== $taxonomies[0] )
        return $args;

    $args['exclude'] = array( 8, 10); // Array of cat ids you want to exclude
    return $args;
}
share|improve this answer
    
Hi Mamaduka, I'd really like to use this, however, no matter how many cat ids I place in the array, the Category count remains unchanged at "16 items". –  N2Mystic Oct 13 '11 at 19:03
    
I tested it on my local dev and it was working just as expected. –  Mamaduka Oct 13 '11 at 19:50
    
@N2Mystic can you check if my code is running? I tested it on my two local dev installations and it works, not sure what is problem with yours –  Mamaduka Oct 14 '11 at 10:03
    
@N2Mystic When testing, be sure to turn off all of your plugins (if it's live, go into maintainance mode - or use a plugin for that). –  kaiser Oct 14 '11 at 10:11
    
Thanks. I'll follow the suggestions and let you know. I appreciate the help :) –  N2Mystic Oct 14 '11 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.