MySQL查询删除重复的WordPress评论? [英] Mysql Query to Delete Duplicate Wordpress Comments?

查看:88
本文介绍了MySQL查询删除重复的WordPress评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Disqus中遇到问题,即它在许多帖子上创建了重复的评论,有时是同一评论的4个重复.我一直在尝试手动删除这些内容,但我们总共收到了超过1万条评论,但不幸的是,这是偶然发生的,因此仅发生在某些帖子中.所以...

I had an issue with Disqus whereby it created duplicate comments on many posts, sometimes 4 duplicates of the same comment. I've been going through to try and manually remove these but we have more than 10K comments total and unfortunately, this happened haphazardly whereby it only happened to some of the posts. So...

有人知道mysql查询吗,通过搜索与注释本身或作者匹配的条目,我可以检测并删除重复的注释?注释ID不是重复的(它为每个注释ID创建了新的注释ID),所以我不确定在mysql中如何做(加上Im不太好:-)...任何帮助将不胜感激.谢谢.

does anyone know of a mysql query whereby I could detect and delete duplicate comments by searching for entries that match in terms of the comment itself or the author? The comment IDs are not duplicate (it created new comment IDs for each) so Im not sure how to do this in mysql (plus Im not very good at it :-)... Any help would be greatly appreciated. Thank you.

推荐答案

根据Blackbarn的建议进行改进,请尝试以下操作(备份数据库后):

Improving on Blackbarn's suggestion, try this (after backing up the db):

global $wpdb;

$comments = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."_comments"
   ." ORDER BY comment_post_ID, comment_content");

$prev = NULL;

foreach($comments as $comment) {

  if ($prev && $prev->comment_content == $comment->comment_content
    && $prev->comment_post_ID == $comment->comment_post_ID ) { // add maybe other rules here

    $wpdb->query("DELETE FROM ".$wpdb->prefix."_comments WHERE comment_ID = ".$comment->comment_ID);

  }
  else
    $prev = $comment;
}

这篇关于MySQL查询删除重复的WordPress评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆