-
-
Save adansuku/b841a1fe79be27ff21c5c066b8457ff1 to your computer and use it in GitHub Desktop.
Show a default month or date range in the calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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