Advertisement
BakerMan

Include child categories in event category queries

Jan 21st, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. // Let's inspect the parameters of any event queries
  2. add_action( 'tribe_events_pre_get_posts', 'tribe_query_include_child_cats' );
  3.  
  4. /**
  5.  * Modifies the taxonomy part of an event query and ensures child categories are included.
  6.  *
  7.  * @param $query
  8.  * @return mixed
  9.  */
  10. function tribe_query_include_child_cats( $query ) {
  11.     // If the tax_query is not specified do not interfere
  12.     $tax_query = $query->get( 'tax_query' );
  13.     if ( ! is_array( $tax_query ) ) return $query;
  14.  
  15.     // Look for include_children flags and set to true
  16.     foreach ( $tax_query as &$component ) {
  17.         if ( is_array( $component ) && isset( $component['include_children'] ) )
  18.             $component['include_children'] = true;
  19.     }
  20.  
  21.     // Update the query
  22.     $query->set( 'tax_query', $tax_query );
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement