0

This is a common query to delete all post revisions:

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision'

Will this work to delete all drafts?

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'draft'

and is it better than this since it also deletes postmeta?

 DELETE FROM posts WHERE post_status = ‘draft’

2 Answers 2

2

draft is not a post_type, it's a post_status. So you should use your second block of code with that substitution:

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_status = 'draft'
0
0

I would suggest if u want to delete any post manually from wp_posts. you need to perform the following steps:-

  1. Remove from postmeta table.
delete FROM wp_postmeta WHERE post_id IN
    (
        select id from wp_posts where post_status='draft'
    );
  1. Remove from wp_term_relationships table.
delete FROM wp_term_relationships WHERE object_id IN
    (
        select id from wp_posts where post_status='draft'
    );
  1. Remove from wp_posts table.
delete from wp_posts where post_status='draft'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.