Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

get_post_time

Function Description:

Retrieves the localized time of the post.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Get the post published time for a specific post ID
$post_id = 123;
$published_time = get_post_time( 'U', false, $post_id );
echo 'The post with ID ' . $post_id . ' was published on ' . date( 'F j, Y, g:i a', $published_time );
// Get the post modified time for the current post
$modified_time = get_post_time( 'U', true );
echo 'This post was last modified on ' . date( 'F j, Y, g:i a', $modified_time );
// Get the post published time in a different timezone
$post_id = 456;
$published_time = get_post_time( 'U', false, $post_id );
$timezone = new DateTimeZone( 'America/New_York' );
$published_time_in_ny = date_create_from_format( 'U', $published_time, $timezone );
echo 'The post with ID ' . $post_id . ' was published on ' . $published_time_in_ny->format( 'F j, Y, g:i a' ) . ' (in New York timezone)';