我一直试图找出如何删除Wordpress数据库中的重复帖子。更具体地说,我希望删除所有与meta_key具有相同meta_value的wp_posts" itemID "在wp_postmeta表中。
换句话说,我不希望2个或更多帖子拥有相同的标题,也不希望相同的" itemID" meta_value,但我不确定如何解决这个问题。
仅供参考,我通常使用的查询在下面。
通过下面的第一个查询,我可以看到重复的meta_values以及重复次数。另外,对于第二个查询,我可以看到哪些帖子是重复的,只有他们的标题(我没有提出这个)
1
SELECT meta_id, post_id, meta_key, meta_value, COUNT( * )
FROM wp_postmeta
WHERE meta_key = '_itemID_'
GROUP BY meta_value
HAVING COUNT( * ) >1
2
SELECT bad_rows.*
from wp_posts as bad_rows
inner join (
select post_title, MIN(id) as min_id
from wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
group by post_title
having count(*) > 1
) as good_rows on good_rows.post_title = bad_rows.post_title
and good_rows.min_id <> bad_rows.id
感谢您寻找圣诞快乐!
答案 0 :(得分:0)
对于具有重复标题的记录,您只需执行此操作:
DELETE FROM wp_posts
WHERE ID NOT IN ( SELECT id FROM(SELECT id,title FROM wp_posts GROUP BY title) )
对于元关键词,您应首先加入两个表并执行相同的操作。