Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active March 3, 2018 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/4fb65c4508da35fddf0a317bc0de36a2 to your computer and use it in GitHub Desktop.
Save cliffordp/4fb65c4508da35fddf0a317bc0de36a2 to your computer and use it in GitHub Desktop.
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