Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. add_action( 'pre_get_posts', 'cyb_pre_get_posts' );
  2. function cyb_pre_get_posts( $query ) {
  3. //Assuming the slug of the custom taxonomy is company-category
  4. //chage it with the correct value if needed
  5. if( $query->is_tax( 'company-category' ) && $query->is_main_query() && !is_admin() ) {
  6. $tax_query = array(
  7. array(
  8. 'taxonomy' => 'company-category',
  9. 'terms' => $query->get( 'company-category' ),
  10. 'include_children' => false
  11. );
  12. $query->set( 'tax_query', $tax_query );
  13. }
  14. }
  15.  
  16. add_filter( 'parse_tax_query', 'cyb_do_not_include_children_in_company_category_archive' );
  17. function cyb_do_not_include_children_in_company_category_archive( $query ) {
  18. if (
  19. ! is_admin()
  20. && $query->is_main_query()
  21. && $query->is_tax( 'company-category' )
  22. ) {
  23. $query->tax_query->queries[0]['include_children'] = 0;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement