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

Tell us what you are trying to do?
I need to have the markers for my seasonal locations be different from my regular locations.
Is there any documentation that you are following?
Toolsets
Is there a similar example that we can see?

What is the link to your site?
hidden link

#1237333

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

I actually worked on a similar solution with this for a customer.

https://toolset.com/forums/topic/how-to-display-a-custom-map-marker-which-is-added-as-a-term-field/#post-1225464

Take a look at the link below.

Thanks,
Shane

#1237353

Hello Shane,

Thanks for that info but Im still a little confused. Reading through that thread it looks like you guys worked through a couple of different options. Im worried that I dont even have it set up the correct way to make this change. As of right now I only have a custom marker for all locations on the map. I need to know how to even start the process of adding a custom marker.

#1237357
1225440-2019_04_03_20_16_02.png

So it looks like he attached different markers directly in the taxonomy type? Is this what I need to be going for?

#1237362

And if so how do I accomplish that?

#1237379

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

This is what he did in his case to attach the markers to the taxonomy in a custom field.
In your case you may not need to do this.

Will your posts have a single term attached to it ? Because if so then you can just use some conditional code to change the markers based on the taxonomy the post has.

Example


[wpv-conditional if="( has_term('Test', 'post_tag', null) eq 'term_slug' )" ]

[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='link to marker icon' marker_field='wpcf-location'][/wpv-map-marker]

[/wpv-conditional]

In order for the has_term() function to work you need to add it to the 3rd party view functions in Toolset -> Settings -> Frontend under "Functions inside conditional evaluations" just add the function name has_term.
https://codex.wordpress.org/Function_Reference/has_term

Please let me know if this helps.
Thanks,
Shane

#1237850

Hell Shane,

What do you mean by term? Are you referring to a specific taxonomy / category that is attached to that particular location?

#1237851

Also what is the post tag the shortcode you provided me with referring to?

#1237854
Screen Shot 2019-04-30 at 12.21.06 PM.png

Hello Shane,
I have added the function has_term. I also put it in the loop editor like this (see attached screenshot ). Its still not working so I think Im not doing something correctly or adding things in the right place. Let me know what exactly I need to adjust.

#1237912

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

Are you referring to a specific taxonomy / category that is attached to that particular location?
Yes the specific term attached to the post.

Also what is the post tag the shortcode you provided me with referring to?
This is in Reference to the slug of the taxonomy, not the term. So if you have a taxonomy called Category then your terms can be beach, pool etc

So you need to provide the slug of the taxonomy.

You've added the shortcode correctly just change post_tag to the slug of the taxonomy.

Thanks,
Shane

#1238164

Hello Shane can you give me a little assistance on this? I just need to know exactly where to put what? So the category/taxonomy of the markers is seasonal. This is within the location post type under location services. I hope Im telling you right? I just need to know where to put the proper term in the proper place of the code you gave me.

#1238166
Screen Shot 2019-05-01 at 9.20.42 AM.png

This is what I have in there now. I just need to know the proper terms for the code. I think I adjusted the post_tag to the slug of the taxonomy. But Its still not showing different markers. Are there other steps other than uploading a new marker and using this code?

#1238186

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

The function has_term() return a boolean, my apologies for the miss-leading information earlier.

It should be eq "1"

Example

[wpv-conditional if="( has_term('Test', 'post_tag', null) eq '1' )" ]
 
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='link to marker icon' marker_field='wpcf-location'][/wpv-map-marker]
 
[/wpv-conditional]

Thanks,
Shane

#1238220
Screen Shot 2019-05-01 at 10.54.54 AM.png

Thanks Shane,

I made that adjustment and it still does not seem to be showing the correct markers yet. Im attaching the updated code with the previous change you informed me to make. Let me know if there is something additional that needs to be done other than add this code.

#1238250

Shane
Supporter

Languages: English (English )

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

Hi Jessica,

This is correct now. However would you mind allowing me to have admin access to debug the code for you ?

I think it would be quicker this way to identify the issue.

Thanks,
Shane