I’m trying to figure out how to display the date that a post was last updated outside of the loop. I’m able to display the published date using get_the_time()
but there doesn’t seem to be a “loopless” function to get the date of the last update.
Does anyone know hot to do this?
6 Answers
It is unclear if you are looking for the last updated post or for the last updated date for some particular post. The answer by @PatJ assumes the former. To do the latter:
$qry = new WP_Query(array('p'=>1));
var_dump($qry->posts[0]->post_modified);
Or…
$date = $wpdb->get_var("SELECT post_modified FROM {$wpdb->posts} WHERE ID = 1");
var_dump($date);
Of course you need to change the post ID to match the post you are looking for.