Snippets: Exclude Passed Events (Events Calendar Plugin) from Total Modules

Note: We recommend this newer snippet instead: https://wpexplorer-themes.com/total/snippets/exclude-past-tribe-events/

add_filter( 'vcex_query_args', function( $args ) {
    $showing_events = false;

    if ( isset( $query_args['post_type'] ) ) {
        if ( is_string( $query_args['post_type'] )
            && 'tribe_events' === $query_args['post_type']
        ) {
            $showing_events = true;
        } elseif ( is_array( $query_args['post_type'] )
            && 1 === count( $query_args['post_type'] )
            && in_array( 'tribe_events', $query_args['post_type'] )
        ) {
            $showing_events = true;
        }
    }

    if ( ! $showing_events ) {
        return $args;
    }

    $exclude_past_events = array(
        'key'     => '_EventStartDate',
        'value'   => date( 'Y-m-d' ) . ' 00:00:00',
        'compare' => '>=',
        'type'    => 'DATETIME'
    );

    if ( isset( $args[ 'meta_query' ] ) && is_array( $args[ 'meta_query' ] ) ) {
        $args[ 'meta_query' ][] = $exclude_past_events;
    } else {
        $args[ 'meta_query' ] = array( $exclude_past_events );
    }

    return $args;

} );
All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)