Skip Navigation

[Resolved] Unique map_id as variable?

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by brentE 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1226664
Cap.jpg

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.

#1226888

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.

#1226895

Thanks Christian, I had missed the mapid="map-1" option in the shortcode docs. That should do the job.

#1226896

My issue is resolved now. Thank you!