WordPress使用三段SQL进行删除重复文章

有很多小伙伴使用WordPress做采集站,不断的采集网络上的文章自动发布到自己的网站上。但采集站最大的问题就是会采集到很多重复文章。此时,我们需要对采集到的重复文章进行去重处理。

图片[1]-WordPress使用三段SQL进行删除重复文章-玩转网 | 902D.Com

本着一惯的原则,我们一般不使用任何第三方工具或插件,此处我们推荐三段SQL来进行文章去重处理。

1、去除重复文章,只保留一篇
CREATE TABLE my_tmp AS SELECT MIN(ID) AS col1 FROM wp_posts GROUP BY post_title;
DELETE FROM wp_posts WHERE ID NOT IN (SELECT col1 FROM my_tmp);
DROP TABLE my_tmp;
2、去除重复文章,一篇都不保留
CREATE TABLE my_tmp AS Select ID AS col1 From wp_posts Where post_title In (Select post_title From wp_posts Group By post_title Having Count(*)>2);
DELETE FROM wp_posts WHERE ID IN (SELECT col1 FROM my_tmp);
DROP TABLE my_tmp;
3、另一种去除所有重复文章的方法
CREATE TABLE my_tmp AS Select ID AS col1 From wp_posts Where post_title In (Select post_title From wp_posts Group By post_title Having Count(*)>2);DELETE FROM wp_posts WHERE ID IN (SELECT col1 FROM my_tmp); DROP TABLE my_tmp;

操作方法很简单,只需将上面的SQL语句(注意修改数据库前缀),放到自己网站数据库的 SQL框里,然后执行就可以了。(注意:操作之前,请先进行网站备份)

© 版权声明

THE END

点赞226赞赏 分享