删除WordPress中的重复帖子

时间:2016-12-26 08:16:25

标签: sql wordpress phpmyadmin

我想删除WordPress网站上的重复帖子 选择重复的帖子工作当前

 SELECT a.ID, a.post_title, a.post_type, a.post_status
    FROM wp_posts AS a
       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 b ON b.post_title = a.post_title
    AND b.min_id <> a.id
    AND a.post_type = 'post'
    AND a.post_status = 'publish'

this query that i need has error
    DELETE a.*
    FROM wp_posts AS a
       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 b ON b.post_title = a.post_title
    AND b.min_id <> a.id
    AND a.post_type = 'post'
    AND a.post_status = 'publish'

这是错误消息:

  

意外的令牌(靠近a)意外的令牌(附近)。意外的令牌   (近*)

1 个答案:

答案 0 :(得分:1)

第一个SELECT帖子ID。然后使用带有DELETE子句的WHERE IN语句。

注意:在执行整个查询之前,请测试IN()子句中的子查询是否返回正确的ID。

DELETE FROM wp_posts
WHERE ID IN (
    SELECT a.ID
    FROM wp_posts AS a
       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 b ON b.post_title = a.post_title
    AND b.min_id <> a.id
    AND a.post_type = 'post'
    AND a.post_status = 'publish'
)