MYSQL命令合集-品图吧

1、草稿文章→已发布

UPDATE wp_posts
SET post_status = 'publish'
WHERE post_status = 'draft'
  AND post_type = 'post';

2、指定分类文章→回收站

UPDATE wp_posts p
INNER JOIN wp_term_relationships tr ON p.ID = tr.object_id
INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
SET p.post_status = 'trash'
WHERE tt.term_id = 123
  AND tt.taxonomy = 'category'
  AND p.post_type = 'post';

3、回收站文章→草稿

UPDATE wp_posts
SET post_status = 'draft'
WHERE post_status = 'trash'
  AND post_type = 'post';

4、指定分类下文章→草稿

UPDATE wp_posts p
INNER JOIN wp_term_relationships tr ON p.ID = tr.object_id
INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
SET p.post_status = 'draft'
WHERE tt.term_id = 123
  AND tt.taxonomy = 'category'
  AND p.post_type = 'post';