How to Automatically Empty Trash Daily or Weekly in WordPress

How to Automatically Empty Trash Daily or Weekly in WordPress featured image

Reading Time: 2 min, 21 sec

WordPress is the most popular blogging platform offering flexibility to use it for other kinds of websites as well. There are lots of things including Posts, Pages, Media, Images, and comments. You can also install plugins for more features or use custom code to use WordPress for other things. It also has a recycle bin-like feature called trash. When we delete some posts or comments, it goes to the trash instead of being permanently removed. This feature is made to avoid accidental deletion of an important article. You can see the link to Trash in the Posts section at the top.

When you delete a blog post, it goes to the trash. WordPress doesn’t delete it permanently. So, if you want to get the post, you can later move it from Trash. When a post is in the trash, it remains in the database and consumes space. If you have a blog about coupons or anything where you frequently delete posts after it is no longer user, you will surely have a lot of posts in Trash. To clean the database, you will have to go to Trash to delete these posts permanently.

Best WordPress Hosting

Bluehost is one of the best and secure WordPress hosting provider

There is also a nice option in WordPress by which you can set your blog to delete all items in the trash automatically on a daily basis. It will reduce your workload and also improve the load time of the blog because queries will take less time to execute.

Empty Trash Automatically in WordPress

If you want to keep trash clean, set it to remove all posts from Trash automatically after certain intervals. For this, you need to edit the wp-config.php file. It will be at the root of WordPress installation. You can either use File Manager of cPanel or FTP to get access to the file. I am not going into the detail of how you can access the FTP or File Manager. I have already explained it multiple times in the past.

Follow these steps:

Open the wp-config.php file. It will be at the root of your WordPress installation. Now add the following code in this file.

define('EMPTY_TRASH_DAYS', 1); //Integer is the amount of days

If you want to schedule it for a week, change 1 to 7. This number is the number of days for which you want to schedule the automatic deletion of trash. If you want to keep posts in the trash for the next 30 days, you can set the value to 30. I keep posts in the trash for 15 days. It all depends on your need.

Now you know how to keep the burden off and keep trash clean. This helps you in keeping the WordPress database clean and remove unwanted items.

Deepanker profile image

Written by Deepanker

Deepanker Verma is an experienced WordPress developer who has been working on WordPress for more than 12 years. On TheWPGuides, he writes about WordPress, WordPress development, and WordPress plugins.

Leave a Reply

Your email address will not be published. Required fields are marked *

Need a Hand with Your WordPress Site?

Don't let technical issues slow you down. Our professional WordPress maintenance service handles updates, security, and performance optimization so you can focus on what you do best: creating content.

Learn More About Our Services