Last active
January 3, 2019 19:41
-
-
Save jpgninja/a234a8e9bb2c14671d609e8f6977187b to your computer and use it in GitHub Desktop.
WordPress Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Delete duplicate WooCommerce products | |
## (Retains the lowest ID) | |
## Pro tip: Change to SELECT to test | |
DELETE bad_rows.* | |
from wp_posts as bad_rows | |
inner join ( | |
select post_title, MIN(id) as min_id | |
from wp_posts | |
where post_type = 'product' | |
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 | |
## (Retains the highest ID) | |
## Pro tip: Change to SELECT to test | |
DELETE bad_rows.* | |
from wp_posts as bad_rows | |
inner join ( | |
select post_title, MAX(id) as min_id | |
from wp_posts | |
where post_type = 'product' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment