I need to exclude a category and its subcategories in posts. This is the code I'm working on and it works:
<?php
$categories = wp_get_post_terms($post->ID, 'category');
$categories = wp_list_filter($categories, array('slug'=>'regione'), 'NOT');
$categories = wp_list_filter($categories, array('slug'=>'lazio'), 'NOT');
$categories = wp_list_filter($categories, array('slug'=>'rm'), 'NOT');
if (!empty($categories)) {
?>
<ul class="category">
<?php
foreach ($categories as $category) {
$cat = get_category($category);
echo '<li><a href="' . get_category_link($category) . '">' . $cat->name . '</a></li>';
}
?>
</ul>
Although, the category 'regione' has more than 20 subcats and each subcat has 5 to 10 other subcats: any suggestion on how to exclude in a better way the main category and its children?