get_post_modified_time
函数
get_post_modified_time ( $format = 'U', $gmt = false, $post = null, $translate = false )
- 参数
-
-
(string)
$format
Optional. Format to use for retrieving the time the post was modified. Accepts ‘G’, ‘U’, or PHP date format. Default ‘U’.- Required: 否
- Default: ‘U’
-
(bool)
$gmt
Optional. Whether to retrieve the GMT time. Default false.- Required: 否
- Default: false
-
(int|WP_Post)
$post
Post ID or post object. Default is global `$post` object.- Required: 否
- Default: null
-
(bool)
$translate
Whether to translate the time string. Default false.- Required: 否
- Default: false
-
(string)
- 返回值
-
- (string|int|false) Formatted date string or Unix timestamp if `$format` is ‘U’ or ‘G’. False on failure.
- 定义位置
-
-
wp-includes/general-template.php
, line 2913
-
wp-includes/general-template.php
- 引入
- 2.0.0
- 弃用
- –
Retrieves the time at which the post was last modified.
function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$source = ( $gmt ) ? 'gmt' : 'local';
$datetime = get_post_datetime( $post, 'modified', $source );
if ( false === $datetime ) {
return false;
}
if ( 'U' === $format || 'G' === $format ) {
$time = $datetime->getTimestamp();
// Returns a sum of timestamp with timezone offset. Ideally should never be used.
if ( ! $gmt ) {
$time += $datetime->getOffset();
}
} elseif ( $translate ) {
$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
} else {
if ( $gmt ) {
$datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
}
$time = $datetime->format( $format );
}
/**
* Filters the localized time a post was last modified.
*
* @since 2.8.0
*
* @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* @param string $format Format to use for retrieving the time the post was modified.
* Accepts 'G', 'U', or PHP date format. Default 'U'.
* @param bool $gmt Whether to retrieve the GMT time. Default false.
*/
return apply_filters( 'get_post_modified_time', $time, $format, $gmt );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。