Skip to content

Instantly share code, notes, and snippets.

@elimn
Created May 24, 2016 14:21
Show Gist options
  • Select an option

  • Save elimn/d90f9a4b1900b0fe4d50eca9f5e0921c to your computer and use it in GitHub Desktop.

Select an option

Save elimn/d90f9a4b1900b0fe4d50eca9f5e0921c to your computer and use it in GitHub Desktop.
MT | TEC | Fast forward to the next month with upcoming events in Month View
<?php
/*
* In month view the month with the first upcoming event is shown
*/
function tribe_fast_forward_month_view( $query ) {
// Dont interfere with other month views (like mini-cal)
if ( ! $query->is_main_query() ) return;
// Dont interfere outside of month view
if ( ! tribe_is_month() ) return;
// 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;
// Set month view to the first upcoming event
if ( ! $query->get( 'eventDate' ) ) $query->set( 'eventDate', $upcoming[0]->EventStartDate );
}
add_action( 'tribe_events_pre_get_posts', 'tribe_fast_forward_month_view' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment