所以这里有一个随机发布日期的小脚本。
$date_format = 'Y-m-d H:i:s';
$date1 = date( $date_format, strtotime("-1 year", time()) );
$date2 = date( $date_format, time() );
$post_type = 'post'; // post, page, product or some other custom post type
// Get all the posts
$posts = get_posts( array(
'numberposts' => -1, // get ALL posts
'post_status' => 'any', // published, pending, draft, future, trash
'post_type' => $post_type
));
foreach( $posts as $post ) {
//* Generate a random post dates
$random_date = mt_rand( strtotime( $date1 ), strtotime($date2) );
//* Format the date that WordPress likes
$post_date = date( $date_format, $random_date );
// We only want to update the post date
$update = array(
'ID' => $post->ID,
'post_date' => $post_date,
'post_date_gmt' => null,
);
//* Update the post
wp_update_post( $update );
}
奥尔多这个线程很老了,我希望这对将来寻找这个答案的人有所帮助。