Last active
May 1, 2017 19:37
-
-
Save andrasguseo/6df4bf6911608bcc33d2deb9c795a37f to your computer and use it in GitHub Desktop.
Set the view to the date with the first upcoming event
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 | |
/* | |
* In month view the month with the first upcoming event is shown | |
* Author: Barry Hughes, Andras Guseo | |
* Last updated: February 17, 2017 | |
*/ | |
add_action( 'tribe_events_pre_get_posts', 'fast_forward_month_view' ); | |
function fast_forward_month_view( $query ) { | |
// Don't interfere with other month views (like mini-cal) | |
if ( ! $query->is_main_query() ) return; | |
// Don't interfere outside of month view | |
// Uncomment the views where you want this to happen. | |
if ( ! tribe_is_month() | |
// && ! tribe_is_list_view () | |
// && ! tribe_is_week() | |
// && ! tribe_is_day() | |
// && ! tribe_is_photo() | |
// && ! tribe_is_map() | |
) return; | |
// If the date is not set, then do what's inside here | |
if ( ! $query->get( 'eventDate' ) ) { | |
// Set the month view to a specific month | |
if ( tribe_is_month() ) { | |
$query->set( 'eventDate', '2017-05-01' ); // <== SET THE DATE (MONTH) YOU WANT TO SHOW HERE | |
} | |
// Other views: set the view to the first upcoming event | |
// Don't forget to uncomment the view above! | |
else { | |
// Get the first upcoming event (bail if there is none) | |
$upcoming = tribe_get_events( array( 'posts_per_page' => 1, 'eventDisplay' => 'list' ) ); | |
if ( empty( $upcoming ) ) return; | |
$query->set( 'eventDate', $upcoming[0]->EventStartDate ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment