Skip to content

Instantly share code, notes, and snippets.

@adansuku
Forked from theeventscalendar/default month.php
Created May 7, 2020 13:24
Show Gist options
  • Save adansuku/b841a1fe79be27ff21c5c066b8457ff1 to your computer and use it in GitHub Desktop.
Save adansuku/b841a1fe79be27ff21c5c066b8457ff1 to your computer and use it in GitHub Desktop.
Show a default month or date range in the calendar
<?php
/**
* Sets the default date for event queries.
*
* Expects to be called during tribe_events_pre_get_posts. Note that this
* function modifies $_REQUEST - this is needed for consistency because
* various parts of TEC inspect that array directly to determine the current
* date.
*
* @param WP_Query $query
*/
function tribe_force_event_date( WP_Query $query ) {
// Don't touch single posts or queries other than the main query
if ( ! $query->is_main_query() || is_single() ) {
return;
}
// If a date has already been set by some other means, bail out
if ( strlen( $query->get( 'eventDate' ) ) || ! empty( $_REQUEST['tribe-bar-date'] ) ) {
return;
}
// Change this to whatever date you prefer
$default_date = '2015-10-01';
// Use the preferred default date
$query->set( 'eventDate', $default_date );
$query->set( 'start_date', $default_date );
$_REQUEST['tribe-bar-date'] = $default_date;
}
add_action( 'tribe_events_pre_get_posts', 'tribe_force_event_date' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment