Home » Wordpress » Query to Delete Posts Older than X Days in WordPress

Query to Delete Posts Older than X Days in WordPress

Posted by: admin November 30, 2017 Leave a comment

Questions:

I run a blog where the community can post time-sensitive community links (sports scores and such). After a certain time, those posts are no longer useful, so I want to delete them in batch via a MySQL query, but I don’t know how. I imagine that getting rid of those posts entirely is more than just deleting from the wp_posts table, right? There other tables at work per post, aren’t there?

I’ve tried a couple of auto- or batch-delete plugins, but they don’t work half the time.

Please, could you provide a MySQL query to delete posts and their pieces older than X days from all relevant tables?

Thank you in advance.

–Nick

Answers:

WordPress has published its database structure in its Codex. Find out more.