How to update post date of page to real time when Visitor access that page?

Example: I write a post on May 28, 2013. And now, when I visit that post, it will change may 28 to June 8.

How to do this?


You can hook into the action the_post (you get the post as parameter here) and run wp_update_post(). Make sure to clean up the date properties and not to run on the admin side or when a post is called in a widget:

is_admin() or add_action( 'the_post', function( $post ) {

    if ( ! is_singular() or ! is_main_query() )

    $post->post_date     = current_time( 'mysql' );
    $post->post_date_gmt = '';

    wp_update_post( $post );

But now you get a write operation on every single request. This will slow down your site. I wouldn’t do that.

  • Thank you ! If this slow down your site, I want to update date time only 1 times per day. How to do this ? Please help me ! – Nguyen Jun 8 '13 at 15:15

You could use wp_update_post in your page template or php page you are using to view the page to update the date of the page everytime it is viewed.

  • Can you help me, please ? I am not coder. So, I don't understand ! – Nguyen Jun 8 '13 at 5:58
  • Sorry had been away, I think you already got the answer from the above since you accepted it. – Suvajit Pal Jun 8 '13 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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