I have a cpt with a date field in it and want to display in a view all records that either have no date at all, or where the date value is gte today()
I have a conditional set up like this
[wpv-conditional if="( $(wpcf-resource-event-date) gte 'today()' ) or ( $(wpcf-resource-event-date) ne '0' )" ]
But i get no results at all. Not sure if its my logic or syntax- or both.
Is it possible to achieve this?
Thanks
Hello,
Please try to modify your codes as below and test again:
[wpv-conditional if="( $(wpcf-resource-event-date) gte 'TODAY()' ) OR ( $(wpcf-resource-event-date) ne '' )"]
More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/#checking-if-a-date-is-today
Luo thanks but this doesn't work- is the logic correct to achieve what I want.
Just to be a bit clearer- Some records have a date - some don't
I want all the records (most with no dates to display) but if there is a date display it only if gte 'today()'
Steve
Dear Steve,
Thanks for the details, I suggest you try these:
[wpv-conditional if="( $(wpcf-resource-event-date) gte 'TODAY()' )"]
wpcf-resource-event-date field is equal or greater than today
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-resource-event-date) eq '' )"]
wpcf-resource-event-date field is empty
[/wpv-conditional]
Yes those work to test the conditions one at a time- but when i string together with an "or" statement I'm not getting the results i should- Is that the correct way to apply both conditionals?
According to your description, the correct way to apply both conditions is using "AND", for example:
[wpv-conditional if="( $(wpcf-resource-event-date) gte 'TODAY()' ) AND ( $(wpcf-resource-event-date) ne '' )"]
...
[/wpv-conditional]
Sorry Luo that doesnt work - it only displays records where the date is gte today() - because they would also have to be not empty so i may still not be making myself clear Here are the conditions
if wpcf-resource-event-date is empty always display
if wpcf-resource-event-date is gte today() display
if wpcf-resource-event-date is lt today() dont' display
Since those separated conditions works:
https://toolset.com/forums/topic/multiple-conditional-statements-in-a-view/#post-1375213
you can combine them as blew:
[wpv-conditional if="( ($(wpcf-resource-event-date) gte 'TODAY()') OR ($(wpcf-resource-event-date) eq '') )" ]
wpcf-resource-event-date field is equal or greater than today OR empty
[/wpv-conditional]
And test again, I have tested above codes in my localhost, it works fine.
My issue is resolved now. Thank you!