Snippets: Exclude Past Events (Tribe Events Calendar) from Theme Grids/Carousels

// Exclude past events from theme grids.
add_filter( 'vcex_grid_query', function( $query_args, $shortcode_atts ) {

	if ( ! function_exists( 'tribe_get_events' ) || empty( $query_args ) ) {
		return $query_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 ) {

		$past_events = array();

		$get_past_events = tribe_get_events( array(
			'end_date' => 'now',
		), false );

		if ( $get_past_events ) {
			foreach ( $get_past_events as $past_event ) {
				$past_events[] = $past_event->ID;
			}
		}

		if ( ! isset( $query_args['post__not_in'] ) ) {
			$query_args['post__not_in'] = $past_events;
		} elseif ( is_array( $query_args['post__not_in'] ) ) {
			$query_args['post__not_in'] = array_merge( $query_args['post__not_in'], $past_events );
		}

	}

	return $query_args;
}, 2, PHP_INT_MAX );
All PHP snippets should be added via a child theme's functions.php file.