I have a site I started but never officially launched. It has many posts and as time passes by they are getting old. Every once in a while I update with a new post and think of a recent launch, but I can’t with some posts dating back as far as 2 years..
Searched for plugins that might do this but none suited me. Finally I added a short code to my “functions.php” that runs only if a special parameter is passed in the URL and updates all the post dates to recent dates with intervals of 1 to 4 days between each.
Here is the first draft of the code just to give you a starting point:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function dates_update() { $my_posts = get_posts( array('post_type' => 'post', 'numberposts' => 100 ) ); $i=0; foreach ($my_posts as $posts) { // random hour and time. You can also manually set these. //$h = rand(1, 23); //$i = rand(0, 59); //calculate dates backwards $timestamp = time(); $tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds $tm = $timestamp - $tm; $postdate = date("Y-m-d", $tm); // [ Y-m-d H:i:s ] $newDate = array( 'ID' => $posts->ID, 'post_date' => $postdate ); wp_update_post($newDate); $i++; } echo('updated'); die; } |
Interested in my help with integration? Need additional customization?
Contact me here: