1

I would like to be able to post the most recent updated date in my footer. However, I can't seem to find a way to do that globally for the site, just for each post/page at a time using get_the_modified_date().

So for example if I make a change to my home page the footer would be updated to that date and time. If I later make an edit to a miscellaneous page, then the "Updated" date and time would change to reflect that more recent update.

Any help is greatly appreciated.

2 Answers 2

1

Just a continuation from mozboz' answer. For those curious as I was, you could use the date() or date_i18n() functions to format the date properly in the following snippet.

function get_latest_update_date() {
    global $wpdb;
    $thelatest = $wpdb->get_var("SELECT max(post_modified) FROM wp_posts WHERE post_type IN ('post', 'page');");
    //returns formatted date like 13.08.2001
    return date_i18n('j.m.Y', strtotime($thelatest));
  }
  
  add_shortcode('latestupdatedate', 'get_latest_update_date');
0

I don't know if there's a more WP-friendly way to do this, but this query will do what you want. It gets the latest date from the posts table for any post or page:

select max(post_modified) from wp_posts where post_type IN ('post', 'page');

So you could wrap that up in a shortcode for example, like:

function get_latest_update_date() {
  global $wpdb;
  return $wpdb->get_var("SELECT max(post_modified) FROM wp_posts WHERE post_type IN ('post', 'page');");
}

add_shortcode('latestupdatedate', 'get_latest_update_date');

If you want to format the date, you'll need to add the PHP date parsing/formatting functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.