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 successfully using the function below to trim the length of my category descriptions when viewing the manage category screen (thanks Rarst).

Suppose I want to remove children of the "uncategorized" category from this listing. Would I simply insert a check in the for loop below to skip over those child items?

UPDATE: With Rarst's tip on using unset(), I've amended the code below with the correct bits to remove specific categories from the manage categories listing...

//Clean up description summaries on Category manage edit table
add_action( 'admin_head-edit-tags.php', 'admin_edit_tags' );
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;
foreach( $terms as $key=>$term )
{
$terms[$key]->description = strip_tags(substr( $term->description, 0, 75 ))."...";
//new bits here
if($terms[$key]->term_id == 1){unset($terms[$key]);}
}
return $terms;
}
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Yes, $terms contains all terms that are retrieved from database for display so whatever changes you make will cascade upwards to interface.

One issue I am not sure about if that will affect pagination of results in this case.

share|improve this answer
    
thanks again. After re-reading my question I can see that it might not be clear that I'm asking to remove the entire category from the loop, not just skip over trimming the description. Does that make sense? Any clues on how I might except a specific category, by id, from getting written to the grid listing? –  Scott B Jan 12 '11 at 20:21
    
@Scott B yes, I understood your question. As I said $terms contains all categories retrieved, so in that loop you check $term for a match to unwanted category and do unset($terms[$key]); on match. I cautiously think it should work. Do you want me to write out code for you? –  Rarst Jan 12 '11 at 20:41
    
Thanks for the tip on unset(), I'll give it a shot. –  Scott B Jan 13 '11 at 2:52
    
I see now why you were concerned about pagination. I'll need to somehow hook into the pagination routine so that it does not include the categories I'm removing from its page count. Otherwise, as I think you were hinting at, the pagination count will definitely be off. –  Scott B Jan 14 '11 at 2:56
add comment

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.