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 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.

Our next available supporter will start replying to tickets in about 0.77 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by martinB-16 3 months, 1 week ago.

Assigned support staff: 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

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

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!