get_post_time
Retrieve the time at which the post was written.
Description
(string|int|false) get_post_time( (string) $d = 'U', (constant) $gmt = false, (constant) $post = null, (bool) $translate = false );
Returns (string|int|false)
Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.
Parameters (4)
- 0. $d — Optional. (string) =>
'U'
- Format to use for retrieving the time the post was written. Either G,, U., or php date format. Default U..
- 1. $gmt — Optional. (constant) =>
false
- Whether to retrieve the GMT time. Default false.
- 2. $post — Optional. (constant) =>
null
-
WP_Post
object or ID. Default is global$post
object. - 3. $translate — Optional. (bool) =>
false
- Whether to translate the time string. Default false.
Usage
if ( !function_exists( 'get_post_time' ) ) { require_once ABSPATH . WPINC . '/general-template.php'; } // Optional. Format to use for retrieving the time the post // was written. Either 'G', 'U', or php date format. Default 'U'. $d = 'U'; // Optional. Whether to retrieve the GMT time. Default false. $gmt = false; // WP_Post object or ID. Default is global $post object. $post = null; // Whether to translate the time string. Default false. $translate = false; // NOTICE! Understand what this does before running. $result = get_post_time($d, $gmt, $post, $translate);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/general-template.php
- 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 );
- }