Delete all drafts?

时间:2018-12-07 作者:BlueDogRanch

这是删除所有后期修订的常见查询:

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\'
这是否可以删除所有草稿?

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\'
既然它也删除了Posteta,那么它是否比这更好呢?

 DELETE FROM posts WHERE post_status = ‘draft’

2 个回复
最合适的回答,由SO网友:Jacob Peattie 整理而成

draft 不是post_type, 这是一个post_status. 因此,您应该将第二块代码用于该替换:

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\'

SO网友:Sumit Jangir

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\'

相关推荐

How jQuery Works in Wordpress

总之,我有一个流媒体网站,我想用jQuery做一个切换按钮来切换到黑暗/光明模式。请查看我的代码,我的代码有什么问题,bcz这对我不适用。在页脚中。php(在正文上方)<div class=\"gelap-terang\"></div> <script> jQuery.noConflict(); jQuery(document).ready(function(){ jQuery(\".gelap-terang\").hi