Skip Navigation

[Resolved] Conditional output based on last modified date

This support ticket is created 6 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
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 5 replies, has 2 voices.

Last updated by Christian Cox 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1155535

Hi

Is it possible to do a conditional output based on the last modified date of a post?

Thanks.

#1155737

Hi, the post date shortcode has an option that will give you access to the last modified date:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-154574
To compare dates, you should probably use the Unix timestamp format "U", which will produce a number. Then you can compare that against some other Unix timestamp. A date custom field value, for example, is stored as a Unix timestamp. So you could compare the post modified date against some custom field value that represents, for example, someone's birthday:

[wpv-conditional if="( '[wpv-post-date type='modified' format='U']' gt '[wpv-post-field name='wpcf-birthdate']' )"]
This post is younger than you!
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-date type='modified' format='U']' gt '[wpv-post-field name='wpcf-birthdate']' )" evaluate="false"]
This post is older than you!
[/wpv-conditional]
#1156855

Hi Christian

Thanks for this information, actually what I was hoping to do was a conditional output based on if the modified date is over over 5 days ago. Is this possible?

Thanks.

#1157336

It's possible with custom code. You would have to determine if the difference between the last modified date timestamp and the current date timestamp is greater than the number of seconds in 5 days:

60 seconds/min * 60 min/hour * 24 hours/day * 5 days = 432000 seconds in 5 days

It would require some knowledge of the PHP date function and custom functions in condtions:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/
http://php.net/manual/en/function.date.php

#1157858

Sure, I have managed to get conditional formatting working with Toolset fields I just can't get it working with this post date modified field.

This is what I am trying:

[wpv-conditional if="( $(wpv-post-date type='modified' format='U') + 432000 gt 'TODAY()' )"]Recently Updated[/wpv-conditional]

Could you help? I can't figure out where I am going wrong.

#1158075

The $ syntax is for use with custom field values. The post modification date must be accessed with the wpv-post-date shortcode instead:

[wpv-conditional if="( [wpv-post-date type='modified' format='U'] + 432000 > 'TODAY()' )"]Recently Updated[/wpv-conditional]

If you're still running into trouble, add the "debug" attribute like this:

[wpv-conditional if="( [wpv-post-date type='modified' format='U'] + 432000 > 'TODAY()' )" debug="true"]Recently Updated[/wpv-conditional]

Some information will be written out to the screen, which can help you understand what's going on.