WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Often i build a site and we have test posts. I was wondering if there's a way via sql to drop all the blog posts with a simple sql query.

Obviously, I would have backed up my previous database before truncating these tables.

I would like to leave the pages alone if possible.

share|improve this question
up vote 2 down vote accepted

You're probably better off doing this with wordpress functions and adding a button which would delete all posts (or even having a shortcode that, when loaded, would do it). The reason I recommend doing this instead of SQL directly is that wp_delete_post() will take all the associated meta with it, which saves you having to do complicated SQL. You can combine this with WP_Query to get posts given a complex set of desired parameters and then loop through them to remove them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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