Wordpress: automatically delete messages preceded by x days?

For a long time I was looking for a plugin that deletes messages that exceed a certain age (for example, 30 days). What is the best way to do this?

0
source share
3 answers

Here is some SQL that will find every message that has been around 30 days or more:

SELECT * FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 30

To delete all messages, you can replace SELECT * FROMwith DELETE FROM- but before doing this, make a backup!

Then you can just cronwhat you like, whether it's a shell script, a PHP script, or whatever you like best.

+5
source
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

Link

+5
source

30- :

delete FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 30
0
source

Source: https://habr.com/ru/post/1729652/


All Articles