Published in: PHP
function exclude_child_cats($query) { if ( is_category() ) : $current_cat = single_cat_title('',false); $current_cat_ID = get_cat_ID("$current_cat"); $ex_cats = get_categories("child_of=$current_cat_ID"); foreach ($ex_cats as $ex_cat) : $excluded[] = $ex_cat->cat_ID; endforeach; $query->set('cat', "$current_cat_ID . $ex"); return $query; endif; } add_filter('pre_get_posts', 'exclude_child_cats');
You need to login to post a comment.
