get_the_date( string $format = '', int|WP_Post $post = null )
Retrieves the date on which the post was written.
Description
Unlike the_date() this function will always return the date.
Modify output with the ‘get_the_date’ filter.
Parameters
- $format
-
(Optional) PHP date format. Defaults to the 'date_format' option.
Default value: ''
- $post
-
(Optional) Post ID or WP_Post object. Default current post.
Default value: null
Return
(string|int|false) Date the current post was written. False on failure.
Source
File: wp-includes/general-template.php
function get_the_date( $d = '', $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
if ( '' == $d ) {
$the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
} else {
$the_date = mysql2date( $d, $post->post_date );
}
/**
* Filters the date a post was published.
*
* @since WP-3.0.0
*
* @param string $the_date The formatted date.
* @param string $d PHP date format. Defaults to 'date_format' option
* if not specified.
* @param int|WP_Post $post The post object or ID.
*/
return apply_filters( 'get_the_date', $the_date, $d, $post );
}
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |