WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to display the date of the latest post updated on : .... ? (7 posts)

  1. southcast
    Member
    Posted 1 year ago #

    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.

  2. Prasath Mani
    Member
    Posted 1 year ago #

    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);
     ?>
  3. keesiemeijer
    moderator
    Posted 1 year ago #

    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

  4. southcast
    Member
    Posted 1 year ago #

    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.

  5. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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();
    ?>
  6. southcast
    Member
    Posted 1 year ago #

    Works like charm. Thanks a million !

  7. southcast
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic