钩子文档

get_lastpostdate

💡 云策文档标注

概述

get_lastpostdate 是一个 WordPress 过滤器,用于修改站点上最新发布文章的日期时间。它允许开发者自定义时间戳的返回值和时区处理。

关键要点

  • 过滤器名称:get_lastpostdate
  • 参数:$lastpostdate(最新发布时间,格式为 'Y-m-d H:i:s' 或 false)、$timezone(时区设置,可选 'server'、'blog' 或 'gmt')、$post_type(文章类型)
  • 时区选项:'server' 使用服务器时区,'blog' 使用站点时区(基于 post_date),'gmt' 使用 GMT 时区(基于 post_date_gmt)
  • 相关函数:get_lastpostdate() 用于检索最新发布时间
  • 版本更新:5.5.0 添加了 $post_type 参数,2.3.0 引入

代码示例

return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone, $post_type );

📄 原文内容

Filters the most recent time that a post on the site was published.

Parameters

$lastpostdatestring|false
The most recent time that a post was published, in ‘Y-m-d H:i:s’ format. False on failure.
$timezonestring
Location to use for getting the post published date.
See get_lastpostdate() for accepted $timezone values.

More Arguments from get_lastpostdate( … $timezone )

The timezone for the timestamp. Accepts 'server', 'blog', or 'gmt'.
'server' uses the server’s internal timezone.
'blog' uses the post_date field, which proxies to the timezone set for the site.
'gmt' uses the post_date_gmt field.
Default 'server'.

$post_typestring
The post type to check.

Source

return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone, $post_type );

Changelog

Version Description
5.5.0 Added the $post_type parameter.
2.3.0 Introduced.