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
#1238251

Shane
Supporter

Languages: English (English )

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

Private fields

#1238261

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

The conditional actually works fine.

Its just that you need to add the other conditional statements for the other terms so that the correct marker is displayed.

Thanks,
Shane

#1238263

Hello Shane,

So since i have multiple different categories would i have to create this conditional statement for each one. Or is there a term I can use in the the if statement ( [wpv-conditional if="( has_term('seasonal', 'location-services', null) eq '1')" ] ) where seasonal is now that would cover all of the other categories?

#1238266

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

You will need to create a separate conditional for each one with each marker in the respective conditional having its own custom marker url.

Thanks,
Shane

#1238267

Hello Shane,

Ok Can you take a look and see whats still wrong. I have created conditional statements for each of the categories and It still is not working properly.

#1238307

Shane
Supporter

Languages: English (English )

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

Hi Jessica.

The conditionals are working fine.

The problem is that you are still using the same marker icons.

[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][/wpv-conditional]
       
       [wpv-conditional if="( has_term('dental-care', 'location-services', null) eq '1')" ]
 	  [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][/wpv-conditional]

If you look at it both marker icons are the same url.

What you need to do is to re-insert the markers for the others and select a different marker for each item.

This should resolve it for you.

Thanks,
Shane

#1238309

Hello Shane,

Just to make sure we are on the same page. I only need different markers for the seasonal locations. All of the other locations will have the same map marker. Take a look again and you will see the first conditional statement has the map market url (hidden link . *note seasonal_map_markers.png). All of the other markers have the same marker url ( hidden link *note map_marker.png ).

#1238313

Shane
Supporter

Languages: English (English )

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

Screenshot 2019-05-01 at 1.11.00 PM.png

Hi Jessica,

I got it to work now.

You actually need to select the icon from the marker icons option. See Screenshot

Should now see the other icon showing up.

Thanks,
Shane

#1238327

Nice thank you so much. The only thing left that I see is removing spyder fi from the map locations. It seems to duplicate the marker. Im trying to find the correct map to remove it.

#1238328

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

Just remove the spiderfy='on' attribute from the map shortcode.

#1238329

I know I just cant seem to locate the view where the map resides.

#1238332

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

Actually the map isn't in a view.

Its actually added directly to the page template .
hidden link

#1238353

Thank you for that. Another issue came up when i removed spiderfy. The seasonal locations (in blue ) do not have a clickable location now like the green markers do. What might be causing this and how can I fix it.

#1238365

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

Are there any items that are being displayed on the map that have the same exact address?

If so then this can be the issue. If there are overlapping markers. The first one to be displayed.

Please let me know so We can check further on this for you.

Thanks,
Shane

#1238366

Hello Shane,

No none have the same address.