Snippets: How to Query Past Events (The Events Calendar).

Below is a sample function you could use to query past events from the Events Calendar Plugin (Tribe Events). This function would be used as a callback in one of the theme's elements such as the Post Cards element via the Advanced Query setting. This could be useful if you want to create a separate page to display all past events if you are currently excluding past events from the grids.

// Custom query args to get past events.
function myprefix_past_events_query_args() {

	$query_args = array(
		'post_type' => 'tribe_events',
		'posts_per_page' => '12',

	if ( ! function_exists( 'tribe_get_events' ) ) ) {
		return $query_args;

	$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__in'] = $past_events;

	return $query_args;



Snippet Type: PHP

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