I have a custom post type “map pins”, that represents our different customers. The purpose of them is to put them on a map Block which I have here. The source for the markers is of course the View for the custom post type next to the map, where I just have a search field and taxonomy filter (I don’t need to display a list of the posts).
I’m trying to figure out how to give the markers a different pin based on the taxonomy, but I’m having some trouble. I looked around a bit for similar questions and from what I can gather, I need to use a conditional, and some additional views? I’m not exactly sure how to implement it. If you could help me in the slightest, it would be much appreciated! 😊
Hello,
You can try with [wpv-conditional] shortcode, check if current post has specific term, then display different map marker shortcode, for example:
1) Dashboard-> Toolset-> Settings-> Front-end Content
In section "Functions inside conditional evaluations", add WordPress function: has_term
2) Use below shortcodes to display different marker shortcode:
[wpv-conditional if="(has_term('my-taxonomy', 'my-term', null) eq '1')"]
[wpv-map-marker map_id="map-1" marker_icon="<em><u>hidden link</u></em>" marker_id='marker-[wpv-post-id]' marker_field="wpcf-address-field-slug" marker_title=" "]
[wpv-post-link]
[/wpv-map-marker]
[/wpv-conditional]
Please replace "my-taxonomy" with your custom taxonomy slug
replace "my-term" with the specific term slug
replace "map-1" with the map ID
replace "hidden link" with the specific specific marker icon URL
replace "address-field-slug" with your custom address field slug
More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker
Hello, thank you for your reply.
So I've added the "has_term" function, and replaced the different slugs and id's etc. with my own values. I'm just not exactly sure where I need to place/save the shortcodes in my content or site?
If you are using WordPress Blocks editor, you can add a shortcode block, and put those shortcodes in it.
More help:
hidden link
That's what I tried actually, but it didn't seem to do anything. The markers are still the default one. I put the shortcode block in the view loop, because I assume it has to check the conditions on every post? So far the only way that I can actually get markers on the map is if I go in the map blocks marker options and make one that has the view block as source. I don't think it's overwriting what the shortcodes is supposed to do, because if I remove it and just keep the shortcodes, no markers get placed anyway.
My shortcodes look as such:
[wpv-conditional if="(has_term('sap-user-type', 'sap-customer-roll-in', null) eq '1')"]
[wpv-map-marker map_id="sap-i-dk-map" marker_icon="<em><u>hidden link</u></em>" marker_id='marker-[wpv-post-id]' marker_field="wpcf-address" marker_title=" "]
[wpv-post-link]
[/wpv-map-marker]
[/wpv-conditional]
It works fine in my localhost, please provide a test site with the same problem, also point out the problem page URLs, I can setup a demo for you.
I have tried the credentials you provided above, but got this message:
An Authentication Code has been sent to the email address associated with your account. Look for an email with "Login Authentication Code" in the subject line.
Please check it, make sure it is a valid admin account, you might need to deactivate "Authentication Code" plugin
Sorry, oversight on my part. Should be good to log in now. Else let me know again.
I'm not sure why but it keeps asking for authentication (I just tried with the account myself) even if I've disabled it. I'm probably overlooking something. I'll let you know when it's disabled.
Okay, it was a setting in iThemes that forced a two-factor authentication for specifically administrators, even if it was disabled on the account... I checked and could log in in without two-factor, so it should (finally) be ready. Sorry for the inconvenience. 🙂
Thanks for the details, I have modified the shortcodes to:
[wpv-conditional if="(has_term('sap-customer-roll-in', 'sap-user-type', null) eq '1')" ]
[wpv-map-marker map_id="sap-i-dk-map" marker_icon="<em><u>hidden link</u></em>" marker_id='customer-marker' marker_field="wpcf-address" marker_title=" "]
[wpv-post-link]
[/wpv-map-marker]
[/wpv-conditional]
Please test again, check if it is fxed.
More help:
https://developer.wordpress.org/reference/functions/has_term/
Seems to do the trick, thank you so much!