Skip Navigation

[Resolved] How to nest HTML Conditional?

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

Problem:
How can we nest HTML conditional?

Solution:
With the GUI you can add consecutive chained conditions in an "AND" or "OR" comparison.

Manually you can elevate that as elaborated here:
https://toolset.com/forums/topic/questin-about-nesting-conditions/#post-610352

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

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

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by katrina 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#610270

I am trying to: Display conditional html content depending on Types Fields and View Shortcodes

Link to a page where the issue can be seen: Not currently live

I expected to see: html displayed conditionally according to my conditions

Instead, I got: html content displayed under unintended circumstances 🙂

I would like to display the text "This is a past event" when the custom post type is EITHER an event or a retreat AND the types field "end-date" has passed. I am using the following code:

[wpv-conditional if="( '[wpv-post-type]' eq 'retreat' ) OR ( '[wpv-post-type]' eq 'event' ) AND ( $(wpcf-end-date) lt 'TODAY' )"]<span style="color:#ef3970;">THIS IS A PAST EVENT</span>[/wpv-conditional]

However, its not working as expected, and I haven't isolated why. I think maybe its not taking into account that i want this text on a retreat post type only if it has an end-date earlier than today. i.e. its currently adding teh text to all retreats, regardless of the end date.

I tried adding an extra "if" like this:

[wpv-conditional if="( '[wpv-post-type]' eq 'retreat' ) OR ( '[wpv-post-type]' eq 'event' ) AND if ( $(wpcf-end-date) lt 'TODAY' )"]<span style="color:#ef3970;">THIS IS A PAST EVENT</span>[/wpv-conditional]

But that didn't do the trick.

I'm hoping there is an obvious mistake that can easily be fixed.

Thank you in advance for any help on this.

#610352
[wpv-conditional if="(  
  ( '[wpv-post-type]' eq 'post_type_one_slug' ) AND ( $(wpcf-date) lt 'TODAY()' ) 
)
OR 
(
  ( '[wpv-post-type]' eq 'post_type_two_slug' ) AND ( $(wpcf-date) lt 'TODAY()' ) 
)"]
 Custom Message
[/wpv-conditional]

I have split up the syntax to make it easier to understand.
When you insert this with the GUI the conditions will be in a chain (AND OR AND are all consecutively executed)
When you instead condition this in chunks you can run each of them one after each other, but in the correct sequence.

You need to slightly adapt what the GUI outputs, manually, so this works properly.

The Code you can insert or adapt to Copa paste is:

[wpv-conditional if="( ('[wpv-post-type]' eq 'post' ) AND ( $(wpcf-date) lt 'TODAY()' )) OR (( '[wpv-post-type]' eq 'toolset-post-type' ) AND ( $(wpcf-date) lt 'TODAY()' ))"]This is your message[/wpv-conditional]
#619256

Thank you Beda - this works perfectly. Thanks for the explanation. You have been extremely helpful as always 😀