Skip to content

Instantly share code, notes, and snippets.

@Shininglow
Created September 4, 2017 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shininglow/9376386f1ad4d5cbed2fbdca9513f23a to your computer and use it in GitHub Desktop.
Save Shininglow/9376386f1ad4d5cbed2fbdca9513f23a to your computer and use it in GitHub Desktop.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment