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.

Leon

Advertisements

Published by

Leon Quinn

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

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

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s