I have some code that generates a Google Map to show a marker based on the location field supplied via a custom field named ‘event_map’. It works great.
<?php
$location = get_field('event_map');
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
</div>
<?php endif; ?>
I now want to add a map that shows ALL of the markers from ALL of the posts from the ‘tour-dates’ custom post type. How would I go about doing this assuming all of these posts have a field called ‘event_map’ to draw location data from? I am stumped and any help appreciated.
Get the posts with such post type and loop on it then use the ACF API
get_field
(the second parameter let us define the post ID in which your custom field value belongs to).This query should get all
tour-dates
posts that have information in theevent_map
field.I’m not sure what you’re using to display the map, so I can’t help beyond that.