Skip Navigation

[Resolved] multiple conditional statements in a view

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

Problem:

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()

Solution:

You can try as blew:
https://toolset.com/forums/topic/multiple-conditional-statements-in-a-view/#post-1376819

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/#checking-if-a-date-is-today

This support ticket is created 5 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by Steve 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1374307

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

#1374411

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

#1374697

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

#1375213

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]
#1375443

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?

#1376013

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]
#1376551

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

#1376819

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.

#1379247

My issue is resolved now. Thank you!