get_post_time

Advertisement

Summery Summery

Retrieve the time at which the post was written.

Syntax Syntax

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

Parameters Parameters

$format

(Optional) Format to use for retrieving the time the post was written. Either 'G', 'U', or PHP date format. Default 'U'.

Default value: 'U'

$gmt

(Optional) Whether to retrieve the GMT time.

Default value: false

$post

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

Default value: null

$translate

(Optional) Whether to translate the time string.

Default value: false

Return Return

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

Source Source

File: wp-includes/general-template.php

	 * @param string $the_modified_date The last modified date.
	 * @param string $format            PHP date format. Defaults to 'date_format' option
	 *                                  if not specified.
	 * @param string $before            HTML output before the date.
	 * @param string $after             HTML output after the date.
	 */
	$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after );

	if ( $echo ) {
		echo $the_modified_date;
	} else {
		return $the_modified_date;
	}

}

/**
 * Retrieve the date on which the post was last modified.
 *
 * @since 2.1.0
 * @since 4.6.0 Added the `$post` parameter.
 *
 * @param string      $format Optional. PHP date format defaults to the date_format option if not specified.
 * @param int|WP_Post $post   Optional. Post ID or WP_Post object. Default current post.
 * @return string|false Date the current post was modified. False on failure.
 */
function get_the_modified_date( $format = '', $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		// For backward compatibility, failures go through the filter below.
		$the_time = false;
	} else {
		$_format = ! empty( $format ) ? $format : get_option( 'date_format' );

		$the_time = get_post_modified_time( $_format, false, $post, true );
	}

	/**
	 * Filters the date a post was last modified.
	 *
	 * @since 2.1.0
	 * @since 4.6.0 Added the `$post` parameter.

Advertisement

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Advertisement

Leave a Reply