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.
[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]
Thank you Beda - this works perfectly. Thanks for the explanation. You have been extremely helpful as always 😀