且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Wordpress:自动删除 x 天前的帖子?

更新时间:2023-12-01 23:19:46

以下是一些 SQL,可以查找已发布 30 天或更长时间的所有帖子:

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

要删除所有帖子,您可以将 SELECT * FROM 替换为 DELETE FROM — 但请确保在执行此操作之前进行备份!

To delete all the posts, you can replace SELECT * FROM with DELETE FROM — but make sure you take a backup before you do this!

然后,您可以随意使用 cron,可以是 shell 脚本、PHP 脚本或任何您最喜欢的脚本.

You can then just cron that however you like, be that a shell script, a PHP script, or whatever you're most comfortable with.