WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to figure out how to display the date that a post was last updated outside of the loop. I'm able to display the published date using get_the_time() but there doesn't seem to be a "loopless" function to get the date of the last update.

Does anyone know hot to do this?

share|improve this question
up vote 3 down vote accepted

It is unclear if you are looking for the last updated post or for the last updated date for some particular post. The answer by @PatJ assumes the former. To do the latter:

$qry = new WP_Query(array('p'=>1));


$date = $wpdb->get_var("SELECT post_modified FROM {$wpdb->posts} WHERE ID = 1");

Of course you need to change the post ID to match the post you are looking for.

share|improve this answer
Thank you, this is what I'm looking for! – Eckstein Apr 14 '13 at 17:15

According to the Codex page for get_the_time(), it needs to be used in The Loop. The difference between the_time() and get_the_time() is that the former echo()es the date, and the latter returns it.

There are a couple functions that do what I think you're looking for -- get the last updated date and time for a post: get_the_modified_time() and get_the_modified_date(). It looks like they too need to be used in The Loop.

Here's one way to get the updated date of the most recent post in your site:

     $args = array(
        'orderby'     => 'post_modified',
        'numberposts' => 1,
    $myposts = get_posts( $args );
    if( have_posts() ) {
        while( have_posts() ) {
            $last_update = get_the_modified_date();
    echo( "Last modified on $last_update." );

If you're sure you need to be outside of any Loops, you can always use $wpdb:

    global $wpdb;
    $sql = "SELECT post_modified
            FROM $wpdb->posts
            WHERE post_type='post'
            AND post_status='publish'
            ORDER BY post_modified DESC
            LIMIT 1";
    $last_update = $wpdb->get_var( $sql );
    echo( "Last updated $last_update." );
share|improve this answer
Thanks. The 2nd code block is more what I'm looking for. – Eckstein Apr 14 '13 at 17:16
Glad you got your answer. – Pat J Apr 14 '13 at 19:33

Another late addition, which may be helpful to know if anyone is looking. You can use these two functions to get the post date and modified date outside the loop.

<?php get_post_time( $d, $gmt, $post, $translate ); ?> 


<?php get_post_modified_time( $d, $gmt, $post, $translate ); ?>

You can read more about these two functions in the codex.

http://codex.wordpress.org/Template_Tags/get_post_time http://codex.wordpress.org/Function_Reference/get_post_modified_time

share|improve this answer

A late addition, but the following snippet can be modified to use most functions outside of the loop:

 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
function wpse95769_modified_date_by_id( $post_id = 0, $format = "F j, Y" ){
    global $post;
    $post = &get_post( $post_id );
    setup_postdata( $post );

    $modified_time = get_the_modified_time( $format );

    wp_reset_postdata( $post );

    return $modified_time;
share|improve this answer

It may not be clear from previous answers, but get_post_time() and get_post_modified_time() can be given a post object or post ID. So, to get the published and modified dates by post ID outside the loop:

$published_time = get_post_time( $date_fmt, null, $post_id );
$modified_time = get_post_modified_time( $date_fmt, null, $post_id );


share|improve this answer

What about the get_lastpostmodified( $timezone ) function?

share|improve this answer
This returns the date when the last post has been modified. So this function is not post-specific but blog-specific - and hence not what was asked for. – tfrommen Feb 4 '14 at 16:55
How would you tell get_lastpostmodified which post you want? – Tom J Nowell Feb 4 '14 at 17:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.