I discovered this resolution nevertheless it’s not working now (I get a deadly error), can anybody please replace the code so its works with WordPress 6.1 (Unique Publish: Replace present submit dates to random dates)
<?php
/**
* Plugin Identify: WPSE 259750 Random Dates
* Description: On activation, change the dates of all posts to random dates
*/
//* We wish to do that solely as soon as, so add hook to plugin activation
register_activation_hook( __FILE__ , 'wpse_259750_activation' );
operate wpse_259750_activation() {
//* Get all of the posts
$posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any' ) );
foreach( $posts as $submit ) {
//* Generate a random date between January 1st, 2015 and now
$random_date = mt_rand( strtotime( '1 January 2015' ), time() );
$date_format="Y-m-d H:i:s";
//* Format the date that WordPress likes
$post_date = date( $date_format, $random_date );
//* We solely wish to replace the submit date
$replace = array(
'ID' => $post->ID,
'post_date' => $post_date,
'post_date_gmt' => null,
);
//* Replace the submit
wp_update_post( $replace );
}
}
I’ve an enormous quantity of posts, I feel on this code attempting to tug all posts at a time so if attainable perhaps we will add a batch system?