Skip Navigation

[Resolved] Conditional syntax if most recent edit was less than 5 minutes ago

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

Problem: I would like to set up a conditional that tests the time of the most recent post edit. If the most recent edit was less than 5 minutes ago, I would like to show some content.

Solution: Use the wpv-post-date shortcode to output a Unix timestamp, subtract that value from NOW(), and compare that value against the number of seconds in 5 minutes (300) using the following syntax:

[wpv-conditional if="( (NOW() - [wpv-post-date type="modified" format="U"] ) lt 300 )"]
...the most recent edit was less than 5 minutes ago...
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/course-lesson/using-toolset-conditional-block/
https://toolset.com/documentation/programmer-reference/forms/cred-conditional-display-engine/
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-154574

This support ticket is created 3 years, 7 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by martinB-16 3 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#2017699

I only want to show a button if the last change to the post is less than 5 minutes old.
This should work with "[wpv-conditional]", "'[wpv-post-date type =' modified '] and" SECONDS_FROM_NOW () ".

But what is the exact syntax?

#2017723

Hello, you'll need to use a conditional that computes the difference between the current time "NOW()" and the modified post date in number of seconds. Then you can compare that difference to the number of seconds in 5 minutes.
- Date format "U" is Unix timestamp format, which is an integer representing a number of seconds.
- NOW() is also a Unix timestamp format, an integer representing a number of seconds.
- Number of seconds in 5 minutes: 5mins * 60secs/min = 300

Conditional setup:

[wpv-conditional if="( (NOW() - [wpv-post-date type="modified" format="U"] ) lt 300 )"]
...the most recent edit was less than 5 minutes ago...
[/wpv-conditional]
#2021199

My issue is resolved now. Thank you!