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.

  • Can you explain what you mean by "static files"? I take that to mean "hard-coded php, html, css, and javascript files" but I have learned not to assume :)
    – s_ha_dum
    May 4 '13 at 1:24
  • Just take the back up of all the wordpress and database now installl new wordpress on your server after that replace the theme and plugin folder to your new wordpress and activate the theme you will get all same site without your previous data if want to add any data rplace the perticular table from your backup database to new database hope this will help you Sep 18 '13 at 4:29

Use WP-CLI to remove all tables from the database in MySQL.

Runs DROP_DATABASE and CREATE_DATABASE MySQL statements using DB_HOST, DB_NAME, DB_USER and DB_PASSWORD database credentials specified in wp-config.php.

wp db reset --yes

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:

  1. backup the current database

  2. 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.

  3. 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.

  • Hi Mophilly, Thanks a lot for detailed answer. I understand importance of backup and do use backup, but thanks for advice. There is a plugin Bulk Delete, but this works only for up to around 1,000 posts (and bit slow) so not solution for me. So in general what you advise me is to recreate website, just without all content that I want to be removed. Test that and if it's fine switch website to this new db. I hope I understand that right - because that is what I just started doing ;)
    – Larson
    Apr 5 '13 at 7:57
  • I was hoping to get some mysql statement (or 3) that will say deleted all posts and meta, all categories and all tags. But as looks like something like this does NOT exist, i will start with thsi process. 1) New WP and clean database 2) move users, etc to new db plus all files from old site 3) test new site, if working switch to that one. I want mark this as resolved yet, as I hope that is some faster solution - some sql statement or similar, as process as above will work, but it is bit slow.
    – Larson
    Apr 5 '13 at 7:57
  • Mophilly, just to say once more that I am very thankful to your detailed answer. Really nice from you.
    – Larson
    Apr 5 '13 at 7:58

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:

$the_query = new WP_Query(array( 'post_type' => 'public_agent', 'posts_per_page' => -1 , 'field' => 'ids'));
    echo $the_query->post_count;
    while ( $the_query->have_posts() ) {
        echo get_the_ID() . ', ';
        wp_delete_post( get_the_ID );

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.