WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

When I delete a bunch of posts their custom fields remain in the database, is there a way to remove them as well on deletion?

share|improve this question
up vote 0 down vote accepted

The best way to do this is to use the wp_delete_post function as follows:

wp_delete_post($post_id, true); //false (default) sends it to the trash

This function accounts for comments, term_relationships, posts.post_parent, and postmeta.

share|improve this answer
Thanks, why doesn't WordPress do that by default when I delete posts from the dashboard? – drtanz Aug 24 '12 at 8:03
It should...... – Brian Fegter Aug 24 '12 at 13:30

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.