Last active
April 23, 2018 14:54
-
-
Save barryhughes/ab991dcf98bfe13125266c9b25fcafa7 to your computer and use it in GitHub Desktop.
Include the same range of events within map view as are shown in list view (ie, include events that are not associated with venues or that are associated with venues which lack geodata)
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 | |
/** | |
* Display the same range of events within map view as are shown in regular list view. | |
*/ | |
add_action( 'init', function() { | |
if ( class_exists( 'Tribe__Events__Pro__Geo_Loc' ) ) { | |
$ecp_geoloc = Tribe__Events__Pro__Geo_Loc::instance(); | |
remove_action( 'tribe_events_pre_get_posts', array( $ecp_geoloc, 'setup_geoloc_in_query' ) ); | |
} | |
} ); | |
/** | |
* Only include map markers with geodata. | |
*/ | |
add_filter( 'tribe_events_ajax_response', function( $response ) { | |
if ( 'map' !== $response['view'] || empty( $response['markers'] ) ) { | |
return $response; | |
} | |
// Remove markers which do not have geodata | |
foreach ( $response['markers'] as $index => $marker ) { | |
if ( strlen( $marker['lat'] ) === 0 && strlen( $marker['lng'] ) === 0 ) { | |
unset( $response['markers'][ $index ] ); | |
} | |
} | |
return $response; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment