Deleting multiple posts in WordPress can be a daunting task, but it doesn’t have to be. There are a few different ways to do it, and the best method for you will depend on how many posts you need to delete and how much control you want over the process.
Method 1: Use the Bulk Delete Option
The easiest way to delete multiple posts in WordPress is to use the built-in bulk delete option. To do this:
- Go to the Posts page in your WordPress dashboard.
- Check the boxes next to the posts you want to delete.
- Click the Bulk Actions drop-down menu and select Move to Trash.
- Click the Apply button.
The selected posts will be moved to the trash. You can restore them from the trash at any time within the next 30 days. After 30 days, they will be permanently deleted.
Method 2: Use a WordPress Plugin
If you need more control over the deletion process, you can use a WordPress plugin. There are a number of plugins available that can help you bulk delete posts. One popular option is the Bulk Delete plugin. To use this plugin:
- Install and activate the Bulk Delete plugin.
- Go to the Posts page in your WordPress dashboard.
- Click the Bulk Delete button.
- In the Select Posts section, select the criteria you want to use to select the posts you want to delete.
- Click the Delete button.
The selected posts will be deleted.
Method 3: Use the WordPress API
If you need to bulk delete posts programmatically, you can use the WordPress API. The following code will delete all posts that were published in the past year:
Code snippet
<?php
// Get all posts published in the past year.
$args = [
'post_status' => 'publish',
'date_query' => [
'after' => date('Y-m-d', strtotime('-1 year')),
],
];
$posts = get_posts($args);
// Delete the posts.
foreach ($posts as $post) {
wp_delete_post($post->ID);
}
?>
Use code with caution.
You can use this code as a starting point to create your own custom script for bulk deleting posts.
Conclusion
Deleting multiple posts in WordPress can be a quick and easy process. By using one of the methods described above, you can quickly and easily remove unwanted posts from your website.
Get a website developer today to help you.