get_post_modified_time() WordPress Function

The get_post_modified_time() function is used to retrieve the post modified time.

get_post_modified_time( string $format = 'U', bool $gmt = false, int|WP_Post $post = null, bool $translate = false ) #

Retrieve the time at which the post was last modified.


Parameters

$format

(string)(Optional) Format to use for retrieving the time the post was modified. Accepts 'G', 'U', or PHP date format.

Default value: 'U'

$gmt

(bool)(Optional) Whether to retrieve the GMT time.

Default value: false

$post

(int|WP_Post)(Optional)WP_Post object or ID. Default is global $post object.

Default value: null

$translate

(bool)(Optional)Whether to translate the time string.

Default value: false


Top ↑

Return

(string|int|false) Formatted date string or Unix timestamp if $format is 'U' or 'G'. False on failure.


Top ↑

More Information

One level »lower« than get_the_modified_time(), but can take more arguments.


Top ↑

Source

File: wp-includes/general-template.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More