You could start from today and just work backwards, one day at a time:
$start_hour = 8;
$end_hour = 17;
$date = new DateTime;
foreach ( $posts as $post ) {
$time = sprintf(
/* Left-pad time values with zeros to two digits */
'%02d:%02d:%02d',
/* Random hour between start and end */
rand( $start_hour, $end_hour ),
/* Random minutes */
rand( 0, 59 ),
/* Random seconds */
rand( 0, 59 )
);
$post_date = $date->format( 'Y-m-d' );
wp_update_post( array(
'ID' => $post->ID,
'post_date' => "$post_date $time",
'post_date_gmt' => null,
));
// Move date 1 day back
$date->modify( '-1 day' );
}
Related Posts:
- How to get the post publish date outside the loop?
- wpdb update add current timestamp not working
- Trying to change database tables storage engine to innodb gives error “invalid default value for ‘post_date'”
- change the year on all of my custom post types?
- SELECT rows between two datetimes when the range is dynamic [closed]
- Removing old_slug and old_date from WordPress Database
- What is this JavaScript “require”?
- How can I make updates to a site, on a development copy, but then move updates back without overriding live site’s evolving database?
- get_results using wpdb
- How can I make a WordPress database portable and url independent?
- wpdb->insert multiple record at once
- How to migrate a HTTPS WordPress installation to localhost?
- How to stop WordPress using utf8mb4_unicode_520_ci collation?
- How to monitor server for error establishing a database connection
- How to create bulk page and content? [closed]
- Default WordPress settings API data sanitization
- Fatal error: Call to undefined function dbDelta()
- Connect to remote database using Localhost install
- remove missing image attachments
- Transient RSS feeds in wp_options not removed automatically?
- Best way to move live site local
- The revisions table in my database is at 70% capacity and growing. What should I do?
- WordPress for a very large website
- How to ensure data consistency in WordPress
- Database location in WordPress
- WooCommerce with thousands of products – site is very slow – optimize db queries? [closed]
- WP_list_table bulk_action get edit and delete
- How to display data from custom table in wordpress database?
- How to intercept update_option() before it saves data?
- Change SQL get_results to search for posts with custom term in custom taxonomy
- wpdb query on custom table not working [closed]
- How to diagnose and keep in check encoding issues?
- Add search Value to wp_list_table pagination
- stdObject stored in database. How does one convert it to usable format?
- Date query not inclusive despite parameter being true
- I have a table I created, how do I make a form for a user to filter the data?
- How to fix unchanged URLs in Database after running serialized search and replace script?
- wp_redirection_404 table has grown to 7GB
- Does WordPress ever need multiple databases?
- Why are no posts showing despite my apparently correct DB restoration?
- What are the “U” and “G” time formats?
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Multiple wp_options tables to share content across installs
- Merging two wp_posts tables while avoiding duplicates
- Merging two databases without borking it
- Is there a smart way to obtain a list of only some selected user meta data?
- Why does importing copies of the database dump and the document root make WordPress data inconsistent?
- Permit Login if table row exists
- Make an Items attribute searchable (taxonomy using existing attribute)
- How Yoast SEO plugin works with variable %%name%%?
- What would Repair and Optimize WordPress Database do?
- MS Access to manage WordPress Database
- Saving zero as meta value
- Query multiple tables at once?
- Custom WordPress Table wpdb
- Sending posts from Python to WordPress
- Problem migrating to localhost
- SQL query to set posts in bulk based on the post content
- Automate WordPress website setup with prefilled data
- Custom search query by category id
- How do you render posts from outside wordpress?
- Image link issues after importing a database backup to my local web server
- multiple wordpress installs w/shared user database but separate content databases
- Second ezSQL initialization for MSSQL
- Fetch a single row from a custom table for to a given ID
- Database create or redirect
- Updating seperate database when post attachment is changed
- add featured image dialog box disappear
- Database structure cheatsheet
- White Screen in Home Page
- WordPress Database – wp_usermeta and the correct number of session_tokens rows
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- How to get a list of articles related to a particular category from my other WordPress website?
- WordPress has been updated! Before we send you on your way, we have to update your database to the newest version
- Malware in old website – how to migrate?
- A WP dev site that displays content from a live site’s database but cannot write to wp_posts?
- error establishing database connection (WAMP + filezilla)
- Is there a way for two deferent themes to consume two different DB on a same WP instance?
- How do I update a WordPress wp_postmeta meta_value that contains many options
- How can I get $wpdb to show MySQL warnings?
- About wp database hooks (error establishing connection)
- How to display $wpdb->insert_id; value on redirected page
- Should I Use only wpdb Class to Write Custom Queries?
- Auto populate form fields based on serial input or pull listings from other websites?
- How to extract some part of WordPress full source code
- Create Tables in WordPress
- Error establishing a database connection for some files
- Hash user emails in database?
- Use the_date with link
- Change the date and time in wordpress
- Weird characters in title if it contain “ ”
- Share WordPress Database
- DB access blocked when initializing WP externally
- Saving data to database and exporting to excel
- Site does not work right, pages not showing up, even for root admin
- Get system timestamp in wordpress
- One information repeated on multiple locations on one site [closed]
- WordPress: Interact with Database Query Data and Login
- Showing Error(TAble already exist)
- Getting an error when trying to migrate to DV server from Grid with Media Temple [closed]