Hide empty categories

Feb 3rd, 2015
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This snippet removes the categories that has no future events on category lists generated by EM
  3. such as via the [event_categories] or the categories page generated by EM.
  5. In its current form, if you supply the include or exclude argument to your shortcode or php function to get categories, this snippet won't take effect.
  7. For instructions on where to paste this, please visit:
  8. */
  9. function em_hide_empty_categories( $args ){
  10.     if( empty($args['exclude']) && empty($args['include']) ){
  11.         //get list of categories with events in them (past or present)
  12.         $terms = get_terms(EM_TAXONOMY_CATEGORY, array('hide_empty'=>true));
  13.         $args['include'] = array();
  14.         foreach( $terms as $term ){
  15.             //check if this term has events in the future, if so add it to the include argument
  16.             if( EM_Events::count(array('category'=>$term->term_id, 'scope'=>'future')) ){
  17.                 $args['include'][] = $term->term_id;
  18.             }
  19.         }
  20.     }
  21.     return $args;
  22. }
  23. add_filter('em_categories_get_default_search', 'em_hide_empty_categories');
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add to your ad blocker whitelist or disable your adblocking software.