Retrieves post published or modified time as a DateTimeImmutable object instance.
Description
The object will be set to the timezone from WordPress settings. For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.Normally this should make no difference to the result. However, the values might get out of sync in database, typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards compatible behaviors in such cases.
Parameters
$postint|WP_Postoptional
Post ID or post object. Default is global $post object.Default: null
$fieldstringoptional
Published or modified time to use from database. Accepts 'date' or 'modified'. Default 'date'.Default: 'date'
$sourcestringoptional
Local or UTC time to use from database. Accepts 'local' or 'gmt'. Default 'local'.Default: 'local'
Return
DateTimeImmutable|false
Time object on success, false on failure.
Uses · 3
get_post()Retrieves post data given a post ID or post object.
wp_timezone()Retrieves the timezone of the site as a `DateTimeZone` object.
Signature, return type and hooks compared across 5 parsed releases.
7.0.4
Parameter $post retyped from int|WP_Post to int|WP_Post|null.verified against source
5.3.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/general-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.