A WordPress-centric search engine for devs and theme authors



get_post_timestamp ›

Since5.3.0
Deprecatedn/a
get_post_timestamp ( $post = null, $field = 'date' )
Parameters: (2)
  • (int|WP_Post) $post Optional. WP_Post object or ID. Default is global `$post` object.
    Required: No
    Default: null
  • (string) $field Optional. Post field to use. Accepts 'date' or 'modified'.
    Required: No
    Default: 'date'
Returns:
  • (int|false) Unix timestamp on success, false on failure.
Defined at:
Codex:

Retrieve post published or modified time as a Unix timestamp.

Note that this function returns a true Unix timestamp, not summed with timezone offset like older WP functions.



Source

function get_post_timestamp( $post = null, $field = 'date' ) {
	$datetime = get_post_datetime( $post, $field );

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

	return $datetime->getTimestamp();
}