Delete Posts

Delete WordPress Posts Older then (X) Days in PHPMyAdmin

I stumbled across this as a possible fix for slow loading and resource hogging websites that have LOTS of content, especially posts numbered in the thousands. Something like the Google spider could use up your sites bandwidth and resources pretty quick if it has to try index thousands of old posts. Most sites might not need to keep older posts live because they will have become irrelevant and outdated over time.

Delete Posts

Login to your hosting control panel then click on the phpMyAdmin icon. Click the name of your sites database then “Export” on the top bar just to make a database backup first in case anything goes wrong. Choose “gzip backup” in advanced settings if your database is huge. Next click the “SQL” title on the top bar and paste the following in the box then click Go bottom right:

DELETE FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 180

What the above SQL command does is delete all blog posts in your site’s database with the posts type “Posts” as opposed to Pages and it deletes everything older than 180 days or 6 months. You can adjust this to suit yourself of course.

Once you’ve done this you might consider installing the Auto Prune Posts WordPress plugin to keep things tidy automatically in future.


Published by

Leon Quinn

Multimedia Design company in Leitrim, Ireland specializing in WordPress Website Design, Photoshop and Graphics.

4 thoughts on “Delete WordPress Posts Older then (X) Days in PHPMyAdmin”

    1. I’m not really sure sorry but it would probably be something like this:

      DELETE * FROM wp_posts WHERE post_type = ‘post’ AND post_date > ‘2012-01-01 00:00:00’ AND post_date < '2017-12-31 00:00:00';


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.