0

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.

1 Answer 1

2

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.

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.