How to Automatically Empty Trash Daily or Weekly in WordPress
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 Managed WordPress HostingWPEngine is the best and most secure managed 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.
Leave a comment
Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.