I have WP website with over 40,000 posts. Now I’ll like to delete all posts, categories and tags. So All content and related meta. All I want to keep is static files. Is there a easy way to do this through database? Some query to drop all relevant tables? Sorry, I am not good with db and code, so please give me detailed explanation or full query. Thanks a lot.
Plugins or any other solution, don’t work for me, I need mysql query.
Leave a Reply
You must be logged in to post a comment.
Use WP-CLI to remove all tables from the database in MySQL.
You wrote that you are not good with database, so please be extremely careful with the advice I present here.
First, learn how to backup your wordpress database and restore it from the backup file. This is critical to save you from catastrophe.
Second, there may be a plugin that will help you. I haven’t looked but a friend was and said he found a “data migration” tool for wordpress.
Next, you can delete data from selected tables. Do not “drop” tables as that will eliminate the data structure in addition to the data. The result will be a broken wordpress. However, there are dependencies you must understand before using the SQL delete command.
A better approach would be learn to use a “selective” restore, loading only the tables that have the data you want to keep, e.g. wp-users. The idea here is to use the backup files to create a “baseline” database setup that suits your purpose.
If you find a data migration tool, you follow this procedure:
backup the current database
create a new database (and wordpress site) and use the migration tool to move data into it. Use the “new” wordpress site to test everything.
If you are successful, then adjust the DNS records to point to the new site. You could adjust the wp config of the original site to point to the database.
Keep in mind the data integrity. It is extremely important.
I hope something in this helps you.
While not instant, if you just need it once it might be more robust just do it through interface.
You can use screen options (top right corner of admin) to increase amount of items per page (I think it handles up to 999, but you might need to set less for it to work properly) and delete them via bulk actions page by page.
I hate posting a link-only answer, but the WordPress Suicide plugin is ideal for deleting almost all the data from a WordPress blog without needing any SQL knowledge.
A create this code:
Is very simple, first get the ids of your custom type, with some filters post_type select the custom type public agent in my case, posts per page select the number of posts, -1 is get all posts and field select the field type i selected only ids.
After the selection i used a while loop for remove all custom posts types with wp_delete_post, passing the id parameter.
I used the plugin debug console (debug bar suite) for run this code.