Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_post_datetime ›

Seit5.3.0
Veraltetn/v
get_post_datetime ( $post = null, $field = 'date' )
Parameter: (2)
  • (int|WP_Post) $post Optional. WP_Post object or ID. Default is global `$post` object.
    Erforderlich: Nein
    Standard: null
  • (string) $field Optional. Post field to use. Accepts 'date' or 'modified'.
    Erforderlich: Nein
    Standard: 'date'
Gibt zurück:
  • (DateTimeImmutable|false) Time object on success, false on failure.
Definiert in:
Codex:

Retrieve post published or modified time as a `DateTimeImmutable` object instance.

The object will be set to the timezone from WordPress settings.



Quellcode

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

	if ( ! $post ) {
		return false;
	}

	$time = ( 'modified' === $field ) ? $post->post_modified : $post->post_date;

	if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) {
		return false;
	}

	return date_create_immutable_from_format( 'Y-m-d H:i:s', $time, wp_timezone() );
}