Create a gist now

Instantly share code, notes, and snippets.

Embed
Events Calendar PRO: Limit Map View to only show today's events by default.
<?php
/**
* Events Calendar PRO: Limit Map View to only show today's events by default.
*
* If the Tribe Bar's date seach was used, display that date, else set it to
* today's date. This operates differently from the default Map View, which
* displays Upcoming Events, not just Today's Events.
*
* @link https://gist.github.com/cliffordp/4fb65c4508da35fddf0a317bc0de36a2
*/
function cliff_tec_map_view_todays_events_by_default( WP_Query $query ) {
if ( ! function_exists( 'tribe_is_map' ) ) {
return;
}
$is_map_view = (
tribe_is_map()
|| Tribe__Events__Pro__Main::instance()->is_pro_ajax_view_request( false, 'map' )
);
$date_specified = (
! empty( $_REQUEST['tribe-bar-date'] )
|| ! empty( $query->get( 'eventDate' ) )
);
if (
$date_specified
|| ! $is_map_view
) {
return;
}
$query->set( 'end_date', current_time( 'Y-m-d' ) );
}
add_action( 'tribe_events_pre_get_posts', 'cliff_tec_map_view_todays_events_by_default', 50 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment