wordpress中常用sql语句

1、开启所有评论

UPDATE wp_posts
SET comment_status = 'open'
WHERE post_status = 'publish';

2、关闭旧文章的留言

UPDATE wp_posts
SET comment_status = 'closed'
WHERE post_date < '2009-01-01' AND post_status = 'publish'

3、删除所有的垃圾评论

DELETE FROM wp_comments
WHERE comment_approved = 'spam'

4、删除所有文章修订版本(Revisions)以及它们的Meta数据

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'

5、清理wp_postmeta表

DELETE FROM wp_postmeta WHERE meta_key = '_wp_old_slug';
DELETE FROM wp_postmeta WHERE meta_key = '_revision-control';
DELETE FROM wp_postmeta WHERE meta_value = '{{unknown}}';