daily pastebin goal
39%
SHARE
TWEET

Hide empty categories

eventsmanager Feb 3rd, 2015 (edited) 365 Never
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.
  4.  
  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.
  6.  
  7. For instructions on where to paste this, please visit: http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
  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
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