Forums

[resolved] How to Merge Comments from more than 2 Topics into a Single one? (8 posts)

  1. WordPress User
    Member
    Posted 2 years ago #

    Hi guys

    How to merge comments from more than 2 wordpress topics into s single topic?

    The case is, I have 3 similar topics in my wordpress blog and I want to delete 2 topics from them. Since I don't want to loose the comments, I want to merge all the comments into a single topic.

    Can anyone please post the MySQL query to do the task?

    Thanks.

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    I'd imagine you can just update the post ID assigned to the relevant comments, so they belong to the post you're keeping.

    I can write the query for you, but i'll need to know the post ID the comments need to be moved to, and the post IDs for the posts that they currently belong to.

  3. WordPress User
    Member
    Posted 2 years ago #

    ^^ Thanks.

    The 2 topics which I want to delete have IDs as following:

    2935 and 2506

    The topic ID which I want to keep:

    1304

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    Assuming you'll run this in phpmyadmin or similar, and you're using wp_ as the prefix for your tables.

    UPDATE wp_comments SET comment_post_ID = 1304 WHERE comment_post_ID IN (2935,2506)

    Please do backup beforehand.

  5. WordPress User
    Member
    Posted 2 years ago #

    ^^ Thanks. The query worked without any problem.

    But! The main topic which now contains all comments, still shows the old comment count. I mean previously, the total comments were 81 in the main topic but now it contains approx. 300 comments after merging other topic comments but it still shows 81 as total comments.

    How to update the comment count?

  6. Mark / t31os
    Moderator
    Posted 2 years ago #

    Run this to get the comment count.

    SELECT COUNT(comment_post_ID) FROM wp_comments WHERE comment_post_ID = 1304 AND comment_approved = 1

    That should give you the new total, jot it down or remember the total, then run this..

    UPDATE wp_posts SET comment_count = XX WHERE ID = 1304

    Replace XX with the total you got from the first query.

    Hope that helps, again backup beforehand, just incase.. ;)

  7. WordPress User
    Member
    Posted 2 years ago #

    Awesome. Thank you so much mate. Worked like a charm. :)

  8. Mark / t31os
    Moderator
    Posted 2 years ago #

    You're welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic