How to Hide Expired Events from the Events Calendar

Home Forums Calendar Products Events Calendar PRO How to Hide Expired Events from the Events Calendar

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1459456
    Mike
    Participant

    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?

    #1460933
    Victor
    Keymaster

    Hi 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,
    Victor

    #1481296
    Support Droid
    Keymaster

    Hey 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

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘How to Hide Expired Events from the Events Calendar’ is closed to new replies.