Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.