Passer la navigation

[Résolu] Display custom map pin based on post taxonomy

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

The customer wanted a Toolset map to show different marker icons based on a post’s taxonomy term, while keeping the marker popup functionality.

Solution:

The solution was to remove the default marker from the Map block settings and add

[wpv-map-marker]

shortcodes manually inside the View loop, wrapped in

[wpv-conditional]

checks for each taxonomy term. The popup content remains available inside the marker shortcode. The customer confirmed it worked. They also noted the earlier issue was likely caused by using two separate HTML blocks inside the loop, one for the marker and one for the post information.

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker

https://toolset.com/forums/topic/different-map-marker-for-each-of-the-terms-within-a-taxonomy-on-map-view/

https://toolset.com/forums/topic/custom-marker-for-each-categorie-taxonomy/

This support ticket is created Il y a 5 days, 2 hours. 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.

Ce sujet contient 1 reply, a 1 voix.

Dernière mise à jour par pabloQ-2 Il y a 2 days, 6 hours.

Assisté par: Christopher Amirian.

Auteur
Publications
#2862027

I'd like the map to display a different pin depending on the post's taxonomy.

I've tried following the steps in this thread, without success: > https://toolset.com/forums/topic/different-map-marker-for-each-of-the-terms-within-a-taxonomy-on-map-view/

For more information:
- I've enabled the has_term filter
- I've removed the marker that appears in the toolset block

I want to achieve something similar to this: > lien caché

Where each map icon indicates the taxonomy of the product type associated with that post.

The site under development is lien caché
You can find the map here: > lien caché

Another thing to keep in mind is that I don't want to lose the pop-up functionality when clicking on the pin.

Thanks,

#2862200

Christopher Amirian
Supporter

Les langues: Anglais (English )

Hi,

Welcome to Toolset support.

For different map pins based on a post taxonomy, the approach from that forum thread is still the right direction: remove the marker from the Map block settings and add the marker shortcode manually inside the View loop, wrapped in conditional checks for each taxonomy term.

The marker shortcode supports the marker_icon attribute, and the popup content is whatever you place between the opening and closing [wpv-map-marker] shortcode, so you should not lose the popup functionality if the shortcode is added correctly. For more information:

https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker

Example structure:

[wpv-conditional if="( has_term('term-slug-1', 'taxonomy-slug', null) eq '1' )"]
[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]-term-1" marker_field="wpcf-address-field-slug" marker_icon="<em><u>lien caché</u></em>"]
Popup content here
[/wpv-map-marker]
[/wpv-conditional]

[wpv-conditional if="( has_term('term-slug-2', 'taxonomy-slug', null) eq '1' )"]
[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]-term-2" marker_field="wpcf-address-field-slug" marker_icon="<em><u>lien caché</u></em>"]
Popup content here
[/wpv-map-marker]
[/wpv-conditional]

Please replace:

- taxonomy-slug with your product type taxonomy slug
- term-slug-1 / term-slug-2 with the actual term slugs
- wpcf-address-field-slug with the Toolset address field slug
- map-1 with the actual map ID from your Map block
- the icon URLs with the final marker image URLs

Also, please see if this would help:
https://toolset.com/forums/topic/custom-marker-for-each-categorie-taxonomy/

Thanks

#2862299

Thanks!

I was able to get what I wanted. I think my mistake was that I was putting two HTML blocks inside the loop, one to generate the map marker and another to generate an information sheet with the post summary. Could this be why it wasn't working?

Anyway, thanks for the quick support!