wordpress删除重复文章标题方法!-泓源视野

wordpress删除重复文章标题方法!

网站最近发现好多文章有重复的,手工一个一个很麻烦,就想到了程序。下面就是WordPress删除重复标题文章的几种方法

一、通过操作SQL数据库删除:
去除重复文章,只保留一篇

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;

去除重复文章,一片都不保留

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;

另一种去除所有重复文章的方法

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框里,然后执行就可以了。(注意:操作之前,请先进行网站备份)

二、php程序删除
require('./wp-load.php');

$strsql="create table my_tmp as select min(ID) as col1 from cd_posts group by post_title";

$strsql1="delete from cd_posts where ID not in (select col1 from my_tmp)";

$strsql2="drop table my_tmp";

$result=mysql_query($strsql);

$result=mysql_query($strsql1);

$result=mysql_query($strsql2);
1
2
3
4
5
6
7
8
9
10
11
12
13
保存以上代码以为delete.php,放在根目录,想要删除重复文章的时候,访问这个文件就可以了。
1
个人实测,方法一里面的第1个完美解决问题。
————————————————
版权声明:本文为CSDN博主「silence cc」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_19339041/article/details/115718437

选中数据库中的表格,然后一句一句执行!

wordpress删除重复文章标题方法!插图

本文由 泓源视野 作者:admin 发表,其版权均为 泓源视野 所有,文章内容系作者个人观点,不代表 泓源视野 对观点赞同或支持。如需转载,请注明文章来源。
1

发表评论

Protected with IP Blacklist CloudIP Blacklist Cloud
您是第8235982 位访客, 您的IP是:[172.69.63.56]