php - Wordpress How to change date format for _get_last_post_time function
问题描述
I am using the _get_last_post_time()
function to show the date of a last added post.
_get_last_post_time( $timezone, array('date','modified'), $post_type);
So far this is all clear, but the output is in 'Y-m-d H:i:s'
format. How do I modify this in a different date format?
Source:
https://core.trac.wordpress.org/browser/tags/5.8/src/wp-includes/post.php#L7076
解决方案
From the
_get_last_post_time
Docs
"This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions."
Use this function instead: get_lastpostdate
Docs
get_lastpostdate
will return a string. After that you could use strtotime
function to convert it to time format. Then you could use date
function to format its output any way you need to, for example:
$last_date = get_lastpostdate();
echo date("M d Y H:i:s", strtotime($last_date));
The above format outputs something like this:
Jul 05 2021 16:30:13
Another example:
echo date("H:i:s", strtotime($last_date));
The above format outputs something like this:
16:30:13
Here is the documentation for formatting date and time in wordpress:
推荐阅读
- java - 从两个 ArrayList 中提取特定连接的对象,组合这些相关对象并从子类中打印
- performance - 列表连接的性能实现为左折叠
- vba - 选择特定列 VBA COPY
- android - 我可以在 NotificationService 中注入我的 RepositoryClass
- user-interface - “信号”(js-signals)和“Observables”(mobx,mobx-react)之间的区别?
- node.js - 通过cookie结果解析奇怪的事情序列
- camunda - 如何限制 Camunda 中的任务执行(无需外部同步)
- kotlin - Kotlin 中默认访问器的实现有哪些
- java - 平板电脑上 api 22(5.1.1) 的毕加索缓存错误
- java - Java 计算属性