Exporting and Importing Comments From Live Site Into Staging Site

Sometimes, during the development work you do on the staging site, comments are added on the live site, so if you want to update the staging site with these new comments, you can do the following:

  • From the live site, click on “update”:
Updating a staging site

  • Then unselect  all database tables except “wp_comments” and “wp_commentmeta,” as shown in this screenshot:
Select database tables

  • After that, update the table comments_count in the staging site’s database. To do that, you can run this SQL query using PhpMyAdmin or the Adminer script:

UPDATE wpstg0_posts, (SELECT COUNT(comment_content) AS total_comments, comment_post_ID
FROM wpstg0_comments WHERE comment_approved = 1
GROUP BY comment_post_ID) x
SET wpstg0_posts.comment_count = x.total_comments
WHERE wpstg0_posts.ID = x.comment_post_ID;

  • Now you are ready to push the staging site to the live site, as it will have the most recent comments data.

Updated on July 16, 2023