Skip to content

Instantly share code, notes, and snippets.

@salvatorecapolupo
Last active September 9, 2022 06:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save salvatorecapolupo/0e2f0ceae8988d43f57dd975d84c340b to your computer and use it in GitHub Desktop.
Save salvatorecapolupo/0e2f0ceae8988d43f57dd975d84c340b to your computer and use it in GitHub Desktop.
WordPress find post duplicates via MySQL query - Used to remove duplicated posts from WordPress - i.e https://www.lipercubo.it, https://capolooper.it
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment