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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With