Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Created August 23, 2016 17:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/295379c665a27090151ad28fd2bf6a96 to your computer and use it in GitHub Desktop.
Save cliffordp/295379c665a27090151ad28fd2bf6a96 to your computer and use it in GitHub Desktop.
Display Past Events in List View if there are no Upcoming Events -- from https://cl.ly/29222x003e22 to https://cl.ly/1z3V0s0Q282Y
<?php
/**
* Display Past Events in List View if there are no Upcoming Events -- from https://cl.ly/29222x003e22 to https://cl.ly/1z3V0s0Q282Y
* By Barry 2016-08-23
* From https://gist.github.com/cliffordp/295379c665a27090151ad28fd2bf6a96
*/
function show_past_events_if_no_future_events( $posts, WP_Query $query ) {
if ( ! $query->is_main_query()
|| ! tribe_is_event_query()
|| ! tribe_is_upcoming()
|| ! tribe_is_list_view()
|| ! empty( $posts )
) {
return $posts;
}
return tribe_get_events( array(
'eventDisplay' => 'past',
'posts_per_page' => 4
) );
}
add_filter( 'posts_results', 'show_past_events_if_no_future_events', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment