September 23, 2020
Annual events (festivals, haunts, etc.) generally occur within the same month each year. Use this function to force update all of your calendar views so scheduled events are seen first without having to navigate through month / week views.
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 = '2017-08'; // where the magic happens
// 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' );
Modified to use dynamic year and specific month:
// updates all views to show current year and specific month
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 = date('Y').'-10'; // year with date function, numerical month
// 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' );