WordPress/SQL: How to Bulk Delete Posts of a Specific Post Type in WordPress
Hello WordPress enthusiasts! 🌟 Need to clean up your site and remove an entire category of posts? This way is a quick and efficient way to bulk delete all posts of a specific post type.
🗑️ Step 1: Database access
Log in to your database administration (e.g. phpMyAdmin) via your hosting control panel or any other method you prefer.
📝 Step 2: Run SQL queries
Use the following SQL queries, but make sure to replace 'record_type' with the actual record type you want to delete. Replace 'wp_' in table names if your table prefix differs from the default value.
DELETE FROM wp_posts WHERE post_type = 'post_type';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts);
The first query deletes posts of the specified post type. The second query removes any associated metadata from deleted posts and the third query deletes relationships to categories/tags.
And that's it! You have now bulk deleted all posts of the selected post type.
⚠️ Always remember to be careful when working directly with the database. An error can have unexpected consequences. If you're not sure, it's a good idea to start by making a full backup of your website or database. This ensures that you have a backup in case something goes wrong.
Do you have any questions? Drop me a comment. Have fun with your WordPress development 🚀