hide subcategories on category pages
-
Hi,
I’d like to hide subcategories from category pages.
I found the following snippet but it isnt working. Does someone have an idea how to do this?/*hide subcategory from category pages*/
function exclude_product_cat_children($wp_query) {
if ( isset ( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query()) {
$wp_query->set(‘tax_query’, array(
array (
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => $wp_query->query_vars[‘product_cat’],
‘include_children’ => false
)
)
);
}
}
add_filter(‘pre_get_posts’, ‘exclude_product_cat_children’);thanks a lot & have a nice week
Cheers,
- The topic ‘hide subcategories on category pages’ is closed to new replies.