Problem: I have a map with markers coming from a View. Each post displayed in the View will have one term assigned from a custom taxonomy. Depending on the assigned term, I would like to display a different marker icon on the map.
Solution: To use custom icons like this based on a taxonomy term, you cannot create the Markers using the configurations available in the Map block. Those Map block side configurations only allow for one icon to be used for all markers. Instead, you'll need to remove all Marker configurations from the Map block and insert a series of conditionals and Marker shortcodes in the View loop block. In a simple scenario there would be one conditional section for each different Marker icon. Here is a simple conditional section you can use as a template:
<!-- day-service icon --> [wpv-conditional if="(has_term('day-service', 'service-type', null) eq '1')"] [wpv-map-marker map_id="map-18" marker_icon="day-service-icon.svg" marker_id='marker-18-[wpv-post-id]' marker_field="wpcf-address"] [wpv-post-link] [/wpv-map-marker] [/wpv-conditional] <!-- other-service icon --> [wpv-conditional if="(has_term('other-service', 'service-type', null) eq '1')"] [wpv-map-marker map_id="map-18" marker_icon="other-service-icon.svg" marker_id='marker-18-[wpv-post-id]' marker_field="wpcf-address"] [wpv-post-link] [/wpv-map-marker] [/wpv-conditional] <!--additional conditional section for each icons should follow here -->
Since this code uses the WordPress function has_term in a conditional clause, you must register has_term in Toolset > Settings > Front-end Content, in Functions inside conditional evaluations.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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)
This topic contains 8 replies, has 2 voices.
Last updated by 3 years, 2 months ago.
Assisted by: Christian Cox.