Question

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’
Était-ce utile?

La solution

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'

Autres conseils

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'
Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top