I have Googled this, but there are always answers to get the modified date of a single post, which I know how to do.
What I'd like to do is get and display the most recent modified date of the most recently modified post.
In other words, if I have 100 posts on a site and someone modifies any one of them, I want to display that date elsewhere on the site.
As in "Most recent site update: March 25, 2018"
I have Googled this, but there are always answers to get the modified date of a single post, which I know how to do.
What I'd like to do is get and display the most recent modified date of the most recently modified post.
In other words, if I have 100 posts on a site and someone modifies any one of them, I want to display that date elsewhere on the site.
As in "Most recent site update: March 25, 2018"
Share Improve this question asked Mar 22, 2018 at 13:26 SteveSteve 3139 silver badges21 bronze badges1 Answer
Reset to default 1Try this:
$q = new WP_Query;
$posts = $q->query( array(
'posts_per_page' => 1,
'orderby' => 'post_modified', // Sorts by the date modified.
'order' => 'DESC', // Sorts in descending order.
'no_found_rows' => true,
) );
// Note that $posts could have more than one post, if your site have sticky
// posts. However, the first post, unless filtered by plugins, would always
// be the most recently modified/updated one.
if ( ! empty( $posts ) ) {
$post = $posts[0];
setup_postdata( $post );
?>
<p>Most recent site update: <?php the_modified_date( 'F d, Y' ); ?>.</p>
<?php
wp_reset_postdata();
}