For a long time, I have searched for a plugin that will delete posts that are over a certain 'age' (eg. 30 days old). What is the best way to do this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here's some SQL that will find every post that has been around for 30 days or more:
SELECT * FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 30
To delete all the posts, you can replace SELECT * FROM
with DELETE FROM
— but make sure you take a backup before you do this!
You can then just cron
that however you like, be that a shell script, a PHP script, or whatever you're most comfortable with.
回答2:
delete a,b,c,d
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 )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE e.term_id =<category id>
AND a.post_type = 'post'
AND DATEDIFF(NOW(), a.post_date) > 30
Reference
回答3:
Delete 30 days old post command is :
delete FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 30