Skip to content

Instantly share code, notes, and snippets.

@askwpgirl
Created April 10, 2024 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askwpgirl/7f42180d042a984015eee09d5b1540e1 to your computer and use it in GitHub Desktop.
Save askwpgirl/7f42180d042a984015eee09d5b1540e1 to your computer and use it in GitHub Desktop.
Display The Events Calendar Past Events in Reverse order
/**
* Changes Past Event Reverse Chronological Order
*
* @param array $template_vars An array of variables used to display the current view.
*
* @return array Same as above.
*/
function tribe_past_reverse_chronological_v2( $template_vars ) {
if ( ! empty( $template_vars['is_past'] ) ) {
$template_vars['events'] = array_reverse( $template_vars['events'] );
}
return $template_vars;
}
// Change List View to Past Event Reverse Chronological Order
add_filter( 'tribe_events_views_v2_view_list_template_vars', 'tribe_past_reverse_chronological_v2', 100 );
// Change Photo View to Past Event Reverse Chronological Order
add_filter( 'tribe_events_views_v2_view_photo_template_vars', 'tribe_past_reverse_chronological_v2', 100 );
@askwpgirl
Copy link
Author

This is from https://theeventscalendar.com/knowledgebase/showing-past-events-in-reverse-order/

By default, TEC counts events from the most recent event according to the pagination rules, then shows the oldest event within that number first.

For example, let's say you have 10 events per year 2019 to 2024.

For past events, it's going to count backwards from your most recent past event, e.g. March 2024 to let's say June 2023.

it will show June 2023 first on the past events, then go to March 2024. To get to further back events, you have to use a lot of mathematical guesswork, since it shows in reverse order in reverse order. Very confusing.

The above code snippet works perfect to display the most recent past events to the oldest events in proper descending, logical order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment