Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove duplicated comments in Wordpress?

Anyone know sql query or wordpress plugin which may help me to remove duplicate comments.

While I was importing posts, comments into wordpress, i got some timeouts, and repeated process, so some of comments posted twice.

like image 928
Mezelderz Avatar asked Jul 13 '26 00:07

Mezelderz


1 Answers

Taking a look at some of the images of WordPress' schema then you should be able to identify the records you want to delete with a query such as

SELECT wp_comments.*
FROM wp_comments
LEFT JOIN (
    SELECT MIN(comment_id) comment_id
    FROM wp_comments
    GROUP BY comment_post_id, comment_author, comment_content
) to_keep ON wp_comments.comment_id = to_keep.comment_id
WHERE to_keep.comment_id IS NULL

You should run the query above and make sure you it is returning the correct records (the ones that will be deleted). Once you are satisfied the query is working then simply change it from a SELECT to a DELETE

DELETE wp_comments
FROM wp_comments
LEFT JOIN (
    SELECT MIN(comment_id) comment_id
    FROM wp_comments
    GROUP BY comment_post_id, comment_author, comment_content
) to_keep ON wp_comments.comment_id = to_keep.comment_id
WHERE to_keep.comment_id IS NULL
like image 183
T I Avatar answered Jul 15 '26 16:07

T I