admin管理员组文章数量:1290946
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.
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.
Share Improve this question asked Jul 30, 2020 at 18:27 IisraelIisrael 1357 bronze badges2 Answers
Reset to default 1Just 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');
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.
本文标签: templatesHow to get the most recent modified date of anything in the footer of my site
版权声明:本文标题:templates - How to get the most recent modified date of anything in the footer of my site? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741506252a2382338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论