Filtering Children of the “uncategorized” Category out of the Loop?

Hi @Scott B:

UPDATE FROM PRIOR ANSWER: Due you my evidently poor reading comprehension skills(!) where I missed the requirement to filter out children (Thanks @Adam BlackStrom for calling attention to my oversight) I’ve modified the code provided.


I think you want to use the list_terms_exclusions filter hook. Add this to your plugin (or others needing the same add to the bottom of your theme’s functions.php file):

function my_list_terms_exclusions($exclusions,$args) {
  $children = implode(',',get_term_children(1,'category'));
  $children = (empty($children) ? '' : ",$children");
  return $exclusions . " AND (t.term_id NOT IN (1{$children}))";
}

Of course the above will affect all category listings which you might not want so you might need to inspect the values in the $args array or more likely inspect other global state to only add the filter criteria only in the context(s) in which you need it.

If you have specifics we of where you need help limiting please ask a follow up question so we can help.

P.S. Also, I agree with Adam. If possible use a custom taxonomy.

Leave a Comment