Skip Navigation

[Resolved] How to have two types of map markers based on taxonomy

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to have custom map markers based on the taxonomy that is attached to the post.

Solution:

In order to do this you will need to make use of the has_term() function. This function return 1 or 0 where 1 is true and 0 is false.

It will check if your post has the term you want attached to it.

Example usage with different markers.


[wpv-conditional if="(has_term('irish-cottage-for-sale', 'listing-type', null) eq '1')"]
 
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_field='wpcf-address_ts' marker_icon='https://cottageology.com/wp-content/uploads/2019/05/red-marker.png']
<span class="marker-feat-img">[wpv-post-featured-image size="medium"]</span><h3>[wpv-post-title]</h3><a class="et_pb_button" href="[wpv-post-url]">View Details</a>
 
[/wpv-map-marker]
 

 
[wpv-conditional if="(has_term('irish-cottage-for-rent', 'listing-type', null) eq '1')"]
 
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_field='wpcf-address_ts' marker_icon='https://cottageology.com/wp-content/uploads/2019/05/green-marker.png']
<span class="marker-feat-img">[wpv-post-featured-image size="medium"]</span><h3>[wpv-post-title]</h3><a class="et_pb_button" href="[wpv-post-url]">View Details</a>
 
[/wpv-map-marker]
 
[/wpv-conditional]

As you can see from the above we are checking 2 different terms in the listing type taxonomy, irish-cottage-for-rent and irish-cottage-for-sale . These are actually the slugs of the terms.

Next all we did was to provide a different marker_icon url for each.

In order for the has_term function to work you need to add it to the custom functions arguments in Toolset -> Settings > Frontend.

This support ticket is created 5 years, 7 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 34 replies, has 2 voices.

Last updated by jessicaM-4 5 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1238371

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jessica,

Should be resolved now.

You were also displaying the marker in the template that was being used for the view. So I removed this.

Your markers should now be showing correctly.

Please let me know if there are any issues.

Thanks,
Shane

#1238373

Thank you so much Shane. The only issue I see not is that the markers are no-longer linking to that location page?

#1238622

I believe I can just adjust the same shortcodes that we adjusted to add the different marker and add in a post tile with link to correct this issue correct? Also If I want to customize the pop up when you click on one of the map markers is this the place that I can do that?

#1238684

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jessica,

For the post title with the link, just use the shortcode [wpv-post-link]

Next to customize the marker area just add your content within the marker shortcode like this.
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='link to marker icon' marker_field='wpcf-location']

Some Content can go here.

[/wpv-map-marker]

Any content within the marker shortcode will show up when the marker is clicked.

Thanks,
Shane

#1238825

My issue is resolved now. Thank you!