Moving the comments your readers have submitted under one of your blog posts to another one might sound like a horrible idea at first, but there are times, especially when the number of comments has increased too much, that such an action is required in order to reduce the page loading time. I am aware of plugins that can arrange comments in multiple pages, but I am against such solutions because they usually add lots of javascript to the HEAD section of the page, so in the end the page does not load any faster at all. On the other hand, it’s not that bad after all to kindly point your readers to a secondary blog post, which has been set up in order to host the discussions about the main post. This obviously should not happen at the release time of the post when the discussion might get hot, but rather at a later time, maybe after several months. Anyway, I am not here trying to convince anyone about the pros and cons of such an action. What I care about, as usual, is the technical part: which would be the most efficient way to move the comments from one post to another?
There are two ways that can make this happen. Each one has its advantages ant disadvantages as outlined below:

By directly manipulating the WordPress database. This is the quickest and most professional way, but running SQL statements is not everyone’s cup of tea.

The second way is not actually about moving the comments, but rather about moving the post itself out of its comments. This is the simplest of the ways and requires zero knowledge of SQL.

Both ways are very safe.

The SQL Way

First of all, create a new post as usual and add any amount of content in it. What you will do is to attach the comments from the old page to the new one.

You will need to know the IDs of your new and old posts. It might not be possible to determine the post ID from the post’s URL as it might not be included in the permalink structure you use. In that case, examine the hyperlinks of the posts in question under the “Manage menu” in the WordPress administration panel.

In the following SQL queries, substitute OLD_ID and NEW_ID according to your posts’ IDs.

Transfer the comments with the following statement:

UPDATE wp_comments SET comment_post_ID=NEW_ID WHERE comment_post_ID=OLD_ID;

That’s it. The comments have been transfered, but we are not done yet.

WordPress keeps the number of each post’s comments hard-coded into the post’s record. This probably serves as a performance booster, but it is necessary to take care of it as well.

Run the following query and take a note of the number in the output. This represents the number of comments under the old post.

SELECT comment_count FROM wp_posts WHERE ID=OLD_ID;

Assume that the numeric result is COMCOUNT.

Then adjust the hardcoded number of comments under the two posts by substituting COMCOUNT, NEW_ID, OLD_ID in the following statements as appropriate:

UPDATE wp_posts SET comment_count=comment_count+COMCOUNT WHERE ID=NEW_ID;
UPDATE wp_posts SET comment_count=comment_count-COMCOUNT WHERE ID=OLD_ID;

You are set.

The WordPress Way

This is called the “WordPress way” because everything takes place within the WordPress administration panel. The general idea is to create a new post identical to the old one and change the old post, which actually has the comments, appropriately so that it is considered as a new post by WordPress.

First of all, create the new post and add content as appropriate.

Second and most important, take a good note of the old post’s “Title“, “Post Slug” and “Post Timestamp“.

Edit the old post‘s “Title“, “Post Slug” and “Post Timestamp” (make sure the “Edit timestamp” checkbox is checked) to some new values and save it.

Edit the new post‘s “Title“, “Post Slug” and “Post Timestamp” to the exact values of the old post (remember the note you had taken?) and publish it.

Done.

Conclusion

This is not a task WordPress users have to accomplish everyday. But, when there is need for it, you will know how to do it. Both ways are safe and complete. Use the one that suits you better.

About George Notaras

George Notaras is the editor of the G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.

About

G-Loaded Journal is a technical blog that publishes news, guides and tutorials about GNU/Linux and other Free Open-Source Software. Our mission is to share our experience and knowledge about system administration, automation and programming.