WordPress Code Snippets

A fresh mix of code snippets and tutorials

Update WordPress Post With Current Time


Here is a simple technique for updating WordPress posts with the current date and time. Useful for timezone/server transfers.

If you’re working with a WordPress-powered site and notice that all date/time information is messed up, you can add the following to the WordPress Loop:

The array that we are passing represents the elements that make up a post. There is a one-to-one relationship between these elements and the names of columns in the wp_posts table in the database. So you can get as specific (or not) as desired.

The key for this technique is to make sure that the post ID, date, and GMT date all are passed with the correct values. And of course we are getting the current time using PHP’s current_time() function.

Note: as explained in the WP Codex, it is important to use this function only in development environments. Learn more details by visiting the reference link below.


Related Posts

Learn more

WordPress Themes In Depth

Show Support

Like our new Facebook Page to show support!