get_the_date

Retrieve the date on which the post was written.

Description

(false|string) get_the_date( (string) $d = '', (null) $post = null ); 

Unlike the_date() this function will always return the date. Modify output with the filter.

Returns (false|string)

Date the current post was written. False on failure.

Parameters (2)

0. $d — Optional. (string) => ''
PHP date format defaults to the date_format option if not specified.
1. $post — Optional. (null) => null
Post ID or WP_Post object. Default current post.

Usage

  1. if ( !function_exists( 'get_the_date' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. PHP date format defaults to the date_format option if not specified. 
  5. $d = ''; 
  6.  
  7. // Optional. Post ID or WP_Post object. Default current post. 
  8. $post = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_the_date($d, $post); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function get_the_date( $d = '', $post = null ) { 
  2. $post = get_post( $post ); 
  3.  
  4. if ( ! $post ) { 
  5. return false; 
  6.  
  7. if ( '' == $d ) { 
  8. $the_date = mysql2date( get_option( 'date_format' ), $post->post_date ); 
  9. } else { 
  10. $the_date = mysql2date( $d, $post->post_date ); 
  11.  
  12. /** 
  13. * Filters the date a post was published. 
  14. * @since 3.0.0 
  15. * @param string $the_date The formatted date. 
  16. * @param string $d PHP date format. Defaults to 'date_format' option 
  17. * if not specified. 
  18. * @param int|WP_Post $post The post object or ID. 
  19. */ 
  20. return apply_filters( 'get_the_date', $the_date, $d, $post );