Skip Navigation

[Resolved] How to show last updated date (not published) in a view loop?

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

Problem:
How to show when a post was last updated, but only if it has been updated since it was published?

Solution:
Use a conditional shortcode to compare the published date and the modified date, like so:

[wpv-conditional if="( '[wpv-post-date]' ne '[wpv-post-date type='modified']' )"]
<p>updated: [wpv-post-date type='modified']</p>
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-date

This support ticket is created 5 years, 10 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by Himanshu Agarwal 5 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1180773

I need to show last update date in a view loop for every item. I used

[wpv-post-date type="modified"]

shortcode to show the last update date, its working fine but if a post is recently published then its showing published date.

I want something like this

if post is published show nothing.

But if a published post updated then show that updated date.

if(post published)
{
//nothing
}elseif(published post updated)
{
Updated on: 09-01-2019
}

Please let me how to make this possible.

#1180853

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If you look in the database at the wp_posts table, you will see that WordPress stores the post_date (when published) and post_modified fields, which the View shortcode wpv-post-date outputs (with or without type="modified").

When a post is published post_modified is set to be equal to post_date, rather than being empty.

So you could use the wpv-conditional shortcode and test whether the post_date and post_modified are not equal, which would mean the post had been updated, e.g.:

[wpv-conditional if="( '[wpv-post-date]' ne '[wpv-post-date type='modified']' )"]
<p>updated: [wpv-post-date type='modified']</p>
[/wpv-conditional]
#1181280

Thank you NIgel.