Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This snippet removes the categories that has no future events on category lists generated by EM
- such as via the [event_categories] or the categories page generated by EM.
- 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.
- For instructions on where to paste this, please visit: http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
- */
- function em_hide_empty_categories( $args ){
- if( empty($args['exclude']) && empty($args['include']) ){
- //get list of categories with events in them (past or present)
- $terms = get_terms(EM_TAXONOMY_CATEGORY, array('hide_empty'=>true));
- $args['include'] = array();
- foreach( $terms as $term ){
- //check if this term has events in the future, if so add it to the include argument
- if( EM_Events::count(array('category'=>$term->term_id, 'scope'=>'future')) ){
- $args['include'][] = $term->term_id;
- }
- }
- }
- return $args;
- }
- add_filter('em_categories_get_default_search', 'em_hide_empty_categories');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement