0

This is my situation.

On 1 Jan 2023 I took a backup on my entire Wordpress database. Let's say that backup contains 100 posts.

Fast forward to today, 14 Feb, and I now have say 125 posts in my Wordpress installation.

If I want to restore/over-write the contents of those original 100 posts as at 1 Jan, how do I do that while keeping the 25 "new" posts untouched?

Obviously all the images I uploaded in the interim will still be on the server too.

It's literally just replacing the post body (i.e. no other meta data, not even the titles) of those 100 original posts using the 1 Jan backup.

1 Answer 1

2

You can import the old wp_posts table in your current database with different table name,

query and loop through it then update the current wp_posts post_content column from the old table where the ID matches.

Here's an example SQL which you can directly do inside phpMyAdmin (this updates everything in single query)

UPDATE wp_posts SET post_content = (
    SELECT post_content 
    FROM temporary_old_wp_posts_backup_table_name
    WHERE `temporary_old_wp_posts_backup_table_name`.`ID` = `wp_posts`.`ID`
    LIMIT 1
)

/* just making sure  the ID exists on old post table ID*/
WHERE EXISTS(
    SELECT 1 FROM temporary_old_wp_posts_backup_table_name
    WHERE `temporary_old_wp_posts_backup_table_name`.`ID` = `wp_posts`.`ID`
)

/* probably need a filter to only update post_type = post*/
AND  post_type = 'post'

Another options is to export the wp_posts from the back-up to a CSV file, loop and read each row and do the same as above (update the post_content of the current post table if ID matches with the id on your csv rows)

Remember to back-up your current database before playing with it. You can also export and import your current database in a new wp install which you can play before running it on live database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.