Skip to content

Instantly share code, notes, and snippets.

@jentheo
Created May 17, 2019 14:41
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 jentheo/9a458ab6980cc9d980efd1e3052eb848 to your computer and use it in GitHub Desktop.
Save jentheo/9a458ab6980cc9d980efd1e3052eb848 to your computer and use it in GitHub Desktop.
Show past events on event category pages
function tribe_set_default_date( $wp_query ) {
// Only run on main event queries
if ( ! tribe_is_event_query() || ! $wp_query->is_main_query() || $wp_query->get( 'eventDate' ) != '') return;
// Set this to the date you want shown, in YYYY-MM-DD format
$date = '2000-01-01';
// Select which TEC views you want this to apply to by uncommenting them
if (
tribe_is_event_category()
// || tribe_is_map()
// || tribe_is_photo()
// || tribe_is_month()
// || tribe_is_week()
// || tribe_is_day()
) {
$wp_query->set( 'eventDate', $date );
}
}
if ( function_exists('tribe_is_event_query') ) {
add_action( 'parse_query', 'tribe_set_default_date', 100);
}
/*
* Sets the date search value to never be blank
*/
function tribe_bar_set_date_val( $filters ) {
global $wp_query;
$new_val = 'value="' . esc_attr( $wp_query->get( 'eventDate' ) ) . '"';
$filters['tribe-bar-date']['html'] = preg_replace( '/value="[^"]*"/', $new_val, $filters['tribe-bar-date']['html'] );
return $filters;
}
add_filter( 'tribe-events-bar-filters', 'tribe_bar_set_date_val', 100, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment