Skip Navigation

[Resolved] Problem with conditionals and custom category markers

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

Problem: I am trying to add conditional HTML that displays different Map Markers depending on the taxonomy term applied to the post. The conditionals do not seem to work, and when I add debug="true" I do not see any debug information printed to the page.

Solution: In this case, the problem is that the conditionals use the function "has_term", which must be registered in Toolset > Settings > Frontend Content > Functions inside conditional evaluations. If it's not registered, the conditionals will fail silently.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

This support ticket is created 6 years, 8 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by glenn 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#769155

I am trying to: get markers based on a taxonomy

Link to a page where the issue can be seen:
This is a page where the view has a conditional included based on a custom taxonomy: hidden link
This is a page with the view without custom taxonomy: hidden link

I expected to see:
Functionality similar to: hidden link

Instead, I got:
hidden link

I have made this functionality on Norface.net before with the help of Shane. However when i try to transfer the functionality to Schuldenlab i get an error. It seems i have set it up exactly the same, however the map/markers won't load because of the conditional statement.

#772613

Hi can you share all the code used to display this map and markers, including the conditional?
Please turn on debugging by adding debug="true" to the conditional so we can see what is happening.

[wpv-conditional if="( ...your conditions here ... )" debug="true"]
...

This will output some information to the front-end. Please share that information with me here.

#785107

Hi,

thank you for your reply. I added the debug to the conditionals. You can see it here: hidden link

The map code is: [wpv-map-render map_id="map-1" scrollwheel="off"]

The list code in the main content is:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->

<wpv-loop>
[wpv-conditional if="( has_term('evenement','mapcategorie',null) eq '1' )" debug="true"]
[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_field="wpcf-locatie" marker_icon="hidden link"][/wpv-map-marker]
<div class="partner-row [wpv-post-taxonomy type="mapcategorie" format="slug" separator=" "]">

[wpv-post-title]


</div>
[/wpv-conditional]

[wpv-conditional if="( has_term('partner','mapcategorie',null) eq '1' )" debug="true"]
[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="hidden link" marker_field="wpcf-locatie"][/wpv-map-marker]
<div class="partner-row [wpv-post-taxonomy type="mapcategorie" format="slug" separator=" "]">

[wpv-post-title]


</div>
[/wpv-conditional]

[wpv-conditional if="( has_term('project','mapcategorie',null) eq '1' )" debug="true"]
[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="hidden link" marker_field="wpcf-locatie"][/wpv-map-marker]
<div class="partner-row [wpv-post-taxonomy type="mapcategorie" format="slug" separator=" "]">

[wpv-post-title]


</div>
[/wpv-conditional]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#785921

Okay, I don't see any debugging information written out to the page here:
hidden link

So there must be something else going on. Can you try the following troubleshooting steps?
- Go to Toolset > Settings > Frontend Content and find the section "Functions inside conditional evaluations". Check to be sure "has_term" is listed here. If not, enter "has_term" and try again.
- Copy the conditionals and paste them again at the top of the loop, but replace the contents with basic text:

[wpv-conditional if="( has_term('evenement','mapcategorie',null) eq '1' )" debug="true"]
evenement
[/wpv-conditional]

[wpv-conditional if="( has_term('partner','mapcategorie',null) eq '1' )" debug="true"]
partner
[/wpv-conditional]

[wpv-conditional if="( has_term('project','mapcategorie',null) eq '1' )" debug="true"]
project
[/wpv-conditional]

What do you see when you test this basic implementation?

#785965

Hi Christian,

once again you have pointed me in the right direction. I spend the better part of a day pulling out my hair on why it was not working. It was indeed the issue that i did not register the script.

Thank you again and have a nice day.

Kind regards,

Glenn