Hi
Is it possible to do a conditional output based on the last modified date of a post?
Thanks.
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]
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.
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
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.
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.