I have a custom post type filled with 7k entries by mistake. I want to empty the database for that custom post type. What is the best way to do it?

2 Answers 2


You can do that by two ways. One is by a function or other by SQL query.

In your function just get all the posts having post_type = <your-custom-post-type> and delete those . Just add that function to theme init method.

You can also do that through just SQL query. Query may be like below.

SELECT * FROM wp_posts WHERE post_type=<your-custom-post_type>

If your are non-technical then second options will be best for your.

Note: Before doing any thing just backup your database for your safety, if any thing goes wrong, you can directly replace the dump.

  • To add to this answer, it's much better to do it through code than direct SQL query because the code method will do some cleanup such as resetting taxonomy counts and deleting post meta. Aug 18, 2014 at 14:16
  • @JohnPBloch That's why I have written that, if he is not a technical person he should do the SQL. Because in the question there is nothing written about the postmeta or any taxonomy. Aug 18, 2014 at 14:32

You should probably look at this plugin... https://wordpress.org/plugins/bulk-delete/

It will provide the functionality you need in a fairly clean interface. Keep in mind there is no "undo" and you should backup your database first.

If you are unfamiliar with that process, try looking at this plugin to assist you... https://wordpress.org/plugins/backupwordpress/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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