Skip Navigation

[Resolved] Different marker images 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 use a different marker based on the Taxonomy of the post.

Solution:

This can be done by using our Conditional shortcode.

An example can be seen below.

[wpv-conditional if="(has_term('bemutatok', 'event_type', null) eq '1')"]
 
[wpv-map-marker map_id="map-3"  marker_icon="https://varadielet.ro/wp-content/uploads/2018/07/bemutato-pin.png" marker_id='marker-[wpv-post-id]-[wpv-attribute name="eid"]' marker_field="wpcf-lokacio" marker_title=" "][wpv-post-link id='[wpv-attribute name="eid"]']<br />Dátum: [convert_date post_field='evcal_srow' post_id='[wpv-attribute name="eid"]' marker_icon='[wpv-post-body view_template="event-marker-image"]']<br />Hely: [wpv-post-link][/wpv-map-marker]
[/wpv-conditional]

What is being down here is that you will need to have a different conditional for each taxonomy term and then switching the markers in each conditional.

Since has_term is a custom function you will need to add it to the views custom functions in Toolset->Settings->Frontend

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Last updated by jozsefG 6 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#984605

Hello

I'm trying to change the marker icons based on taxonomy (hidden link). I tried to use this solution: https://toolset.com/forums/topic/different-marker-image-in-a-single-map. I'd already got help from you to set up my nested view.

https://toolset.com/forums/topic/show-markers-set-in-linked-post-type/
https://toolset.com/forums/topic/convert-non-types-date-field-timestamp-to-date/

The loop in my child view which lists the markers looks like this:

[wpv-map-marker map_id="map-3" marker_id='marker-[wpv-post-id]-[wpv-attribute name="eid"]' marker_field="wpcf-lokacio" marker_title=" "][wpv-post-link id='[wpv-attribute name="eid"]']<br />Dátum: [convert_date post_field='evcal_srow' post_id='[wpv-attribute name="eid"]' marker_icon='[wpv-post-body view_template="event-marker-image"]']<br />Hely: [wpv-post-link][/wpv-map-marker]

The view template looks like this:

[wpv-conditional if="(has_term('bemutatok', 'event_type', null) eq '1')"]<em><u>hidden link</u></em>
[wpv-conditional if="(has_term('fesztivalok', 'event_type', null) eq '1')"]<em><u>hidden link</u></em>
...

Of course I registered has_term in settings for conditionals.

Unfortunately this solution is not working, the marker stays the default one.

Maybe it would be better if I'd give you from the start access to my admin to see this nested view for yourself...

#993296

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

Thank you for contacting our support forum.

Yes i'll enable the private fields for you to provide the credentials.

Also please send me a link to the page where this is setup.

Thanks,
Shane

#1011330

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

Not sure if you tried this as yet but doesn't seem so from the view.

[wpv-conditional if="(has_term('bemutatok', 'event_type', null) eq '1')"]

[wpv-map-marker map_id="map-3"  marker_icon="<em><u>hidden link</u></em>" marker_id='marker-[wpv-post-id]-[wpv-attribute name="eid"]' marker_field="wpcf-lokacio" marker_title=" "][wpv-post-link id='[wpv-attribute name="eid"]']<br />Dátum: [convert_date post_field='evcal_srow' post_id='[wpv-attribute name="eid"]' marker_icon='[wpv-post-body view_template="event-marker-image"]']<br />Hely: [wpv-post-link][/wpv-map-marker]
[/wpv-conditional]

Notice i've added the marker_icon attribute, so I use the conditional to check and then display the item with a custom marker.
Please let me know if this helps.

Thanks,
Shane

#1013883

Tried it now, added all the 7 if statements to the view, now the view is not working at all.

#1069307

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

I see why this isn't working and it's because the taxonomy term you are checking is not attached to the Hylek CPT. Its actually attached to the Parent CPT.

In order to check for the taxonomy it must be attached to the current post tht the view is displaying.

Thanks,
Shane

#1069348

Please tell me how to do this? Because I create the markers in the helyek child view, which means places in Hungarian.
After I can show the markers differently based on event type I'll also have to create a filter for those event types and have checkboxes to show only the selected event types.

#1069352

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

What you need to do is to set that event type taxonomy to attach to the Helyek CPT and then add the appropriate taxonomy to each of the posts.

Thanks,
Shane

#1069353

But how could that be possible? I have events with an event type taxonomy. I cannot give that event type to a Place (helyek).

#1069355

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

I logged in and edited the Event Type taxonomy using Types so now it should show up on the Helyek CPT.

Now whats needed is to attach the posts to the correct taxonomy term.

Please let me know if this helps.

Thanks,
Shane

#1069366

You added Event Type to a PLACE (Helyek = places). A pub for example cannot have an Event Type, that belongs to Events. That's why I set up two CPT's because there are separate things. An event can take place in multiple Places and a Place can host infinite number of events in many categories. That's why I have a many to many relationship. I cannot give an Event Type taxonomy to a Place, that's totally incorrect.

I'll have to present Events and Places too, every Event will have a post where the Place is listed, and every Place will have it's own post where you can view it's upcoming events and it's past events as image galleries. Do you understand the logic of this site?

#1069368

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

I understand what you're saying about this, however in your case you want to change the map markers based on the Event Type.

We are using the conditional statement to check the event type, however the has_term function will check the current post. This would mean its checking the Helyek CPT and not the event CPT.

From what we have we know that the Helyek CPT doesn't have the Event Type Taxonomy attached to it, so all the conditionals will return false.

The logic of the site is clear but in achieving the specific detail of the different marker would require some breaking of the logic.

What you can do tho if you don't want to use the taxonomy you will need some way of marking the Helyek with some event type so that the markers can be changed.

Thanks,
Shane

#1069374

But it is not possible to break this logic... Because you cannot set only one event type to a place. Because it would show for example a concert marker for a sports event...

Is it possible another approach maybe?

I understand that the conditionals are in the child view for another CPT but in the same child view I have marker informations from the Parent view, like event date... You helped me with that if I'm not mistaken.

After this is solved I'll also have to create a custom filter for those event types and have checkboxes to show only the selected event types. This won't be possible either?

#1069376

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

I'm thinking of an idea that might work.

We might be able to pass the taxonomy of the parent into the child view and use the conditionals based on that value.

I'll set it up so you can use it as an example for future reference.

Thanks,
Shane

#1069378

Thanks Shane, you're great!

Maybe if you can tell me about setting up those custom filters too... I expect it to be complicated just like this...

#1069381

Shane
Supporter

Languages: English (English )

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

Hi Jozsef,

It seems that we are getting somewhere.

Now the markers are showing again.

This is the conditional I used.

 [wpv-conditional if="('[wpv-attribute name='term']' eq 'koncertek')"]
          	[wpv-map-marker map_id="map-3" marker_id='marker-[wpv-post-id]-[wpv-attribute name="eid"]' marker_field="wpcf-lokacio" marker_title=" "][wpv-post-link id='[wpv-attribute name="eid"]']<br />Dátum: [convert_date post_field='evcal_srow' post_id='[wpv-attribute name="eid"]' marker_icon="<em><u>hidden link</u></em>"]<br />Hely: [wpv-post-link][/wpv-map-marker]
          [/wpv-conditional]

Also this is how I passed the attribute in the child view.

[wpv-view name="child-view-helyek-posts" eid="[wpv-post-id]" term='[wpv-post-taxonomy type="event_type" format="slug"]']

For the custom filters this can be added to the parent view so that you can filter it from there. This wouldn't be an issue since if the parent view filters then the child view is filtered as well because its dependent on what the parent is displaying.

Thanks,
Shane