WordPress at a glance

get_post_time() WP 2.0.0

Gets the time of the current post creation in the specified format. You can specify a return format (the default is Unix format). Must be used in WordPress loop.

The function gets a result for processing in php, and does not display it to the screen. Use the_time() to display the result.

Is the basis for: get_the_time()
Works based on: mysql2date()
Hooks from the function

String/Int/false. Formatted date string or Unix timestamp if $d is 'U' or 'G'. False on failure.


get_post_time( $d, $gmt, $post, $translate );
Format to use for retrieving the time the post was written. Either 'G', 'U', or php date format.
Default: 'U'
Whether to retrieve the GMT time.
Default: false
WP_Post object or ID.
Default: global $post object
Whether to translate the time string.
Default: false


#1 Get the timestamp of the post

To get a Unix timestamp of a post adjusted for the GMT time zone (the second parameter), you can use the function like so:

$gmt_timestamp = get_post_time( 'U', true );
echo $gmt_timestamp; //> 1521992006


Since 2.0.0 Introduced.

Code of get post time: wp-includes/general-template.php WP 5.2.3

function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;

	if ( $gmt ) {
		$time = $post->post_date_gmt;
	} else {
		$time = $post->post_date;

	$time = mysql2date( $d, $time, $translate );

	 * Filters the localized time a post was written.
	 * @since 2.6.0
	 * @param string $time The formatted time.
	 * @param string $d    Format to use for retrieving the time the post was written.
	 *                     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_time', $time, $d, $gmt );

Related Functions

From tag: date time

More from category: Posts, pages...

More from Template Tags: Posts, Pages, ...

vladlu 100vlad.lu
Editors: kama 100
No comments
    Hello, !     Log In . Register