I need display last modified date of most recent modified post in out of loop.
-
1What have you tried so far? Where do you want to display the date - front end or back end? On what page/archive/content type?– WebElaineCommented Jan 9, 2020 at 14:15
-
If you haven't seen the top related question then there's a nice answer there too, saving the last modified date in options.– RupCommented Jan 9, 2020 at 15:29
Add a comment
|
1 Answer
This works for me. Place this in your functions.php
file:
function prefix_last_modified_date() {
$last_modified_date = null;
$args = array(
'post_type' => 'post', // could be page, or a CPT
'orderby' => 'modified',
'post_count' => 1,
);
$last_modified = new WP_Query( $args );
if ( $last_modified->have_posts() ) {
$last_modified->the_post();
$last_modified_date = get_the_modified_date();
}
wp_reset_postdata();
return $last_modified_date;
}
Then you can display the last modified post date anywhere in your theme:
echo prefix_last_modified_date();