Home › Forums › Calendar Products › Events Calendar PRO › How to Hide Expired Events from the Events Calendar
- This topic has 3 replies, 2 voices, and was last updated 6 years, 2 months ago by Mike.
-
AuthorPosts
-
February 20, 2018 at 10:54 pm #1459456MikeParticipant
We host hundreds of events every month, so the monthly view can be a slow load. To cut down on load time, is there a way to hide all of the events that have expired from the calendar, so that it loads quicker?
February 22, 2018 at 7:47 am #1460933VictorKeymasterHi Mike!
Thanks for reaching out! Happy to help you with this topic.
You can hide past events using the following snippet.
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100); function filter_tribe_all_occurences ($wp_query) { if ( !is_admin() ) { $new_meta = array(); $today = new DateTime(); // Join with existing meta_query if(is_array($wp_query->meta_query)) $new_meta = $wp_query->meta_query; // Add new meta_query, select events ending from now forward $new_meta[] = array( 'key' => '_EventEndDate', 'type' => 'DATETIME', 'compare' => '>=', 'value' => $today->format('Y-m-d H:i:s') ); $wp_query->set( 'meta_query', $new_meta ); } return $wp_query; }
I haven’t tested much and might need extra adjustments but I believe that is a good starting point to achieve what you are looking for.
Also, let me point you to the following article about caching the month view > https://theeventscalendar.com/knowledgebase/caching-month-view-transients/
Hope it helps. 🙂
Best,
VictorMarch 16, 2018 at 9:35 am #1481296Support DroidKeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘How to Hide Expired Events from the Events Calendar’ is closed to new replies.