WP mysql queries

by | Aug 4, 2022 | Uncategorized

Cleans up metadata from metadata table from posts that have been deleted:

SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;

credit: https://www.inmotionhosting.com/support/edu/wordpress/cleaning-up-old-post-meta-data-in-wordpress/

Delete duplicate posts:

DELETE bad_rows.*
from wp_posts as bad_rows
inner join (
select post_title, MIN(id) as min_id
from wp_posts
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

credit: https://cleverplugins.com/delete-duplicate-posts-wordpress/

Disclaimer: Please keep in mind that we may receive a commission when you click on our links and make a purchase. This, however, has no bearing on our reviews and comparisons.

Subscribe to our newsletter for more website tips!

12 + 3 =

0 Comments

8 Steps To Website SEO

Free! 8 Steps To Website SEO

Join our mailing list to receive the latest news and updates from our team.

You have successfully subscibed! Soon you will receive an email with your free 8 steps to SEO.