I'm building a tourism site that will have a lot of Google maps filtered by location, destination type, etc. I've created a couple of views that pass the required variables via shortcode, e.g.
[wpv-view name="map-view" wpvdestlocation="Lanark Highlands"]
This works for a single map on a page but not for multiple, presumably because the loop has a fixed map_id set, e.g.
<wpv-loop>
[wpv-map-marker map_id='map-3' marker_id='marker-[wpv-post-id]' etc
Is there a way to make the value of map_id a variable, so that each map on a page has a unique ID?
This isn't a dealbreaker but definitely a nice-to-have.
Is there a way to make the value of map_id a variable, so that each map on a page has a unique ID?
If your map shortcode is inside a View, then you can pass a value into that View using a shortcode attribute and access that value with the wpv-attribute shortcode. For example:
[wpv-view name="Your View containing map marker shortcodes" mapid="map-1"]
Then inside the View:
[wpv-map-marker map_id='[wpv-attribute name="mapid"]' marker_id='marker-[wpv-post-id]' ...etc...
This technique is called passing arguments to Views: https://toolset.com/documentation/user-guides/passing-arguments-to-views/
If you need something more flexible, you could create a custom post type that represents each Map, then create a View that loops over those Maps. Nest your View of Markers inside that View of Maps.
Thanks Christian, I had missed the mapid="map-1" option in the shortcode docs. That should do the job.
My issue is resolved now. Thank you!