skip to Main Content

WordPress Code Snippets


Hide Past Events from The Events Calendar

This snippet focuses your listings on upcoming events, improving user experience.

add_filter('tribe_events_pre_get_posts', 'hide_past_events');
function hide_past_events($query) {
    if (!is_admin() && $query->is_main_query() && $query->is_post_type_archive('tribe_events')) {
        $query->set('meta_query', array(
            array(
                'key' => '_EventStartDate',
                'value' => date('Y-m-d H:i:s'),
                'compare' => '>=',
                'type' => 'DATETIME',
            ),
        ));
    }
    return $query;
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search