I have 7000 posts published on October 31, 2021. What SQL should I use to change the date for all those posts to Feb 1, 2022?
I run a WordPress site with MySQL 5.7.37 and PHP 7.4.
Honestly, I have no idea of anything.
Any help to change the date in bulk for thousands of posts at once will be much appreciated.
Looking forward to some help from experts!
CodePudding user response:
Exactly as already mentioned in comments.
UPDATE posts SET post_date = '2022-02-01' WHERE post_date = '2021-10-31';
Double-check the post_date format first though, as it may be in long number format etc.
CodePudding user response:
If you're going to update post date from your theme / plugin's code then you can use $wpdb
to run the SQL command. Something like this:
global $wpdb;
$query = $wpdb->query( "UPDATE $wpdb->posts SET post_date = '2022-02-01 00:00:00' WHERE post_date LIKE '2021-10-31%'");
Note: $wpdb->posts
returns the name of your post table dynamically so you don't have to remember the post table name.
If you're going to use the command directly from phpmyadmin
then just use
UPDATE wp_posts SET `post_date` = '2022-02-01 00:00:00' WHERE `post_date` LIKE '2021-10-31%'