SHARE
TWEET

Include child categories in event category queries

BakerMan Jan 21st, 2014 122 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top