Skip Navigation

[Resolved] Adding different marker image on a single map using taxonomies

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

Problem:
How to display different map marker image or icon or pin based on different category or taxonomy terms

Solution:
You can add different marker shortcode with different marker image and wrap the marker shortcode using [wpv-conditional] shortcode which will help you to display correct marker image based on category or taxonomy term.

you can find proposed solution with the following reply:
https://toolset.com/forums/topic/adding-different-marker-image-on-a-single-map-using-taxonomies/#post-593382

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/

This support ticket is created 6 years, 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 3 voices.

Last updated by Nicola Inwood 6 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#590697

I am trying to: add different marker images based on taxonomy of posts

Link to a page where the issue can be seen:

I expected to see:

Instead, I got: hidden link

Followed the instructions on this post https://toolset.com/forums/topic/different-marker-image-in-a-single-map/ and i did not get different image markers. Not sure where my misstep has been. I have 6 markers that should be displayed but I only see one default marker.

#590806

The solution in that Thread is related to a Map displayed in a Loop of a View, where you have the Post Object of each post available and can check on it's term.

This will not work in a single Post as there only one post object is available and you cannot display several addresses for one post depending on terms as there is always only one set of terms per post.

Now, if this is in a View's loop, it works just fine, but I am not sure why Luo suggests such a complex approach.

You can do that much simpler.

1. Add the View where you will plot the map
2. Insert something like this in the Loop:

<!-- wpv-loop-start -->
[wpv-map-render map_id="map-1"]
  <wpv-loop>
    [wpv-conditional if="(has_term('term-name', 'taxonomy-slug', null) eq '1')"]
      [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_field="wpcf-address"][/wpv-map-marker]
    [/wpv-conditional]

    [wpv-conditional if="(has_term('term-name', 'taxonomy-slug', null) eq '1')"] 
      [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_field="wpcf-address"][/wpv-map-marker]
    [/wpv-conditional]
  </wpv-loop>
<!-- wpv-loop-end -->

3. Register the WordPress native has_term() function in Toolset > Settings > Front End Content > Functions inside conditional evaluations
4. Add terms to the posts where you also add addresses

Of course the above conditional needs to be adapted to your needs.

But this is the working syntax of the MVS (Minimum Viable Solution).

Thank you.

#591675

Beda.

I did want to do exactly what the other user successfully accomplished, one map, all posts with different icons. How do I Map displayed in a Loop of a View, where you have the Post Object of each post available and can check on it's term.

I successfully did have all posts in the map view but when i started to add the code in the previous support thread i somehow obtained a map with one post view.

Can you walk me through it. I would really appreciate it. I think it is a great feature but obviously I am just not getting it right.

#592713

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello Nicola Inwood,

Beda is on vacation. This is Minesh here and I'll take care of this ticket and try to help you further. Hope this is OK.

Could you please share problem URL and tell me what issues you are facing I'm happy to walk with you until your problem get resolved.

I have set the next reply to private which means only you and I have access to it.

#592940
#593382

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now.

I've modified your view's loop output as given under:

<wpv-loop>
      [wpv-conditional if="(has_term('animal-gives', 'type-of-give', null) eq '1')"]
      
           [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_field="wpcf-address-where-you-completed-your-give"][/wpv-map-marker]
      [/wpv-conditional]
      
       [wpv-conditional if="(has_term('environment-gives', 'type-of-give', null) eq '1')"]
      [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_field="wpcf-address-where-you-completed-your-give"][/wpv-map-marker]
      
      [/wpv-conditional]
      
      [wpv-conditional if="(has_term('people-gives', 'type-of-give', null) eq '1')"]
           [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_field="wpcf-address-where-you-completed-your-give"][/wpv-map-marker]
      [/wpv-conditional]
	</wpv-loop>

And I've registered the "has_term" function at:
=> Toolset => Settings => Frontend content tab => Functions inside conditional evaluations

Now, I can see the different pins as per your category assigned. You can change the marker image as per your need.

Simply, try to add new marker with your choice marker image.

#593511

MInesh

Thank you so much for this. I was not expecting you to add it all, but it was a beautiful surprise this morning.

The client will be thrilled that they have this option now..thank you.

Nicola

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.