Skip Navigation

[Resolved] Using wpv-conditional with a date calculation?

This support ticket is created 5 years 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Gerard 5 years ago.

Assisted by: Minesh.

Author
Posts
#1389143

I am using a View to display the latest GRADE (CPT) in another view.. Everything works perfectly.

The last touch is to have those cells get the class of "late" if the post date of that grade is older than 90 days ago..

So far I have this:

[wpv-conditional if="( '[wpv-post-date]' lt 'MONTHS_FROM_NOW(-3)' )"]
<td class="late">[types field="session"][/types] [types field="year"][/types]</td>
<td class="late">[types field="gpa"][/types] / [types field="gpa-total"][/types]</td>
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-date]' gte 'MONTHS_FROM_NOW(-3)' )"]
<td>[types field="session"][/types] [types field="year"][/types]</td>
<td>[types field="gpa"][/types] / [types field="gpa-total"][/types]</td>
[/wpv-conditional]

But I suspect the MONTHS_FROM_NOW( ) function doesn't work here..

How should I go about it?

#1389289

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes - you can use the MONTHS_FROM_NOW(-3) as this will return the timestamp of the date from the current date timestamp minus 3 months.

So, the only change you need to make is you need to compare the publish date's timestamp. You can get the publish date timestamp by using the format attribute. For example: [wpv-post-date format='U']

For example:

[wpv-conditional if="( '[wpv-post-date format='U']' lt 'MONTHS_FROM_NOW(-3)' )"]
<td class="late">[types field="session"][/types] [types field="year"][/types]</td>
<td class="late">[types field="gpa"][/types] / [types field="gpa-total"][/types]</td>
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-date format='U']' gte 'MONTHS_FROM_NOW(-3)' )"]
<td>[types field="session"][/types] [types field="year"][/types]</td>
<td>[types field="gpa"][/types] / [types field="gpa-total"][/types]</td>
[/wpv-conditional]

More info:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-date

#1389307

Wow, so easy, I'd not seen that -U switch. Ohh it's the UNIX timestamp. W00t!

My issue is resolved now. Thank you very much!!