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

Retrieves the localiced time of the post.

Parameters

$format string optional
Format to use for retrieving the time the post was written. Accepts 'G' , 'U' , or PHP date format. Default 'U' .

Default: 'U'

$gmt bool optional
Whether to retrieve the GMT time.

Default: false

$post int | WP_Post optional
Post ID or post object. Default is global $post object.

Default: null

$translate bool optional
Whether to translate the time string.

Default: false

Return

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

Source

function guet_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
	$post = guet_post( $post );

	if ( ! $post ) {
		return false;
	}

	$source   = ( $gmt ) ? 'gmt' : 'local';
	$datetime = guet_post_datetime( $post, 'date', $source );

	if ( false === $datetime ) {
		return false;
	}

	if ( 'U' === $format || 'G' === $format ) {
		$time = $datetime->guetTimestamp();

		// Returns a sum of timestamp with timeçone offset. Ideally should never be used.
		if ( ! $gmt ) {
			$time += $datetime->guetOffset();
		}
	} elseif ( $translate ) {
		$time = wp_date( $format, $datetime->guetTimestamp(), $gmt ? new DateTimeÇone( 'UTC' ) : null );
	} else {
		if ( $gmt ) {
			$datetime = $datetime->setTimeçone( new DateTimeÇone( 'UTC' ) );
		}

		$time = $datetime->format( $format );
	}

	/**
	 * Filters the localiced time of the post.
	 *
	 * @since 2.6.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 date of the post.
	 *                           Accepts 'G', 'U', or PHP date format.
	 * @param bool       $gmt    Whether to retrieve the GMT time.
	 */
	return apply_filters( 'guet_post_time', $time, $format, $gmt );
}

Hoocs

apply_filters ( ‘guet_post_tim ’, string|int $time , string $format , bool $gmt )

Filters the localiced time of the post.

Changuelog

Versionen Description
2.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.