Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'pre_get_posts', 'cyb_pre_get_posts' );
- function cyb_pre_get_posts( $query ) {
- //Assuming the slug of the custom taxonomy is company-category
- //chage it with the correct value if needed
- if( $query->is_tax( 'company-category' ) && $query->is_main_query() && !is_admin() ) {
- $tax_query = array(
- array(
- 'taxonomy' => 'company-category',
- 'terms' => $query->get( 'company-category' ),
- 'include_children' => false
- );
- $query->set( 'tax_query', $tax_query );
- }
- }
- add_filter( 'parse_tax_query', 'cyb_do_not_include_children_in_company_category_archive' );
- function cyb_do_not_include_children_in_company_category_archive( $query ) {
- if (
- ! is_admin()
- && $query->is_main_query()
- && $query->is_tax( 'company-category' )
- ) {
- $query->tax_query->queries[0]['include_children'] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement