Skip Navigation

[Resolved] Custom markers for custom taxonomies

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, 8 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 4 replies, has 2 voices.

Last updated by orlaF 5 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1238765

I have followed this support document: https://toolset.com/forums/topic/different-marker-image-in-a-single-map/

Here is where I am showing my test directory: hidden link

My Content Template named 'marker image' is as follows:
[wpv-conditional if="(has_term('irish-cottage-for-sale', 'listing-type', null) eq '1')"]hidden link;
[wpv-conditional if="(has_term('irish-cottage-to-rent', 'listing-type', null) eq '1')"]hidden link;

My Marker shortcode is:
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_field='wpcf-address_ts' marker_icon='[wpv-post-body view_template="marker image"]']<span class="marker-feat-img">[wpv-post-featured-image size="medium"]</span><h3>[wpv-post-title]</h3>View Details[/wpv-map-marker]

The map is showing the correct location but no markers (See Screenshot: hidden link). What am I getting wrong here?

I can get one single type of marker to show for both listings by using the following marker shortcode without the content template:
[wpv-map-marker map_id='map-1' marker_id='marker-1' marker_title='[wpv-post-title]' marker_field='wpcf-address_ts']<h3>[wpv-post-title]</h3><span class="marker-feat-img">[wpv-post-featured-image size="medium"]</span>View Details[/wpv-map-marker]
See Screenshot: hidden link

Thank you for your help
Kind Regards,
Orla

#1238796

Shane
Supporter

Languages: English (English )

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

Hi Orla,

Thank you for contacting our support forum.

From what I can see here you are providing a content template for the marker icon which should only be a url.
marker_icon='[wpv-post-body view_template="marker image"]

So the marker_icon = "url to icon image"

Example


[wpv-map-marker map_id='map-13' marker_id='marker-[wpv-post-id]' marker_icon='<em><u>hidden link</u></em>' marker_field='wpcf-location'][/wpv-map-marker]

Please let me know if this helps.
Thanks,
Shane

#1238801

Hi Shane,

That would just show a single marker for all listings which is the default behaviour and works just fine - I am trying to display different markers for each category term which is why I am using the content template following the instructions given here - https://toolset.com/forums/topic/different-marker-image-in-a-single-map/

Kind Regards,
Orla

#1238821

Shane
Supporter

Languages: English (English )

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

Hi Orla,

The best option is to wrap the marker itself in the conditional code rather than loading the marker through the content template.

Example.

[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='<em><u>hidden link</u></em>;
<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]

[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='<em><u>hidden link</u></em>;
<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]

Please let me know if this helps.
Thanks,
Shane

#1238840

That worked - thank you Shane!

Kind Regards,
Orla