Advertisement
eventsmanager

Hide empty categories

Feb 3rd, 2015
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement