Support » Fixing WordPress » How to display the date of the latest post updated on : …. ?

  • Resolved southcast

    (@southcast)


    I need an expert to suggest me a piece of code or a snippet to display a result something like this :

    LAST UPDATED : August 30, 2012.

    This has to be displayed site-wide perhaps somewhere on the header area. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,

    You can access the database directly and find the “newest” post or page updated.

    <?php $newest = $wpdb->get_row("select post_modified from $wpdb->posts
    where post_type in ('page', 'post') and post_status = 'publish' order by post_modified desc");
     echo mysql2date('m/d/Y',$newest->post_modified);
     ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    Inside the loop you can use the_modified_date():

    <?php the_modified_date( 'F j, Y', 'last updated: '); ?>

    http://codex.wordpress.org/Function_Reference/the_modified_date

    I seem to have asked wrong question. My apologies. What I would actually like to have is to display the date of the last published post and I will need to paste in the header somewhere. Thank You.

    Michael

    (@alchymyth)

    Forum Moderator

    for the last modified date (of any modified post);
    something like:

    <strong>LAST UPDATED</strong>: <?php
    $last_updated = get_posts('posts_per_page=1&orderby=modified');
    foreach( $last_updated as $post ) { setup_postdata($post); the_modified_date(); }
    wp_reset_postdata();
    ?>

    for the last published date;
    something like:

    <strong>LAST UPDATED</strong>: <?php
    $last_updated = get_posts('posts_per_page=1&orderby=date&order=DESC');
    foreach( $last_updated as $post ) { setup_postdata($post); the_date(); }
    wp_reset_postdata();
    ?>

    Works like charm. Thanks a million !

    Guess i need to mark this as resolved. Thanks everybody.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to display the date of the latest post updated on : …. ?’ is closed to new replies.