Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Last active April 23, 2018 14:54
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 barryhughes/ab991dcf98bfe13125266c9b25fcafa7 to your computer and use it in GitHub Desktop.
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)
<?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