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?

1 Answer 1


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.

  • Thanks, why doesn't WordPress do that by default when I delete posts from the dashboard?
    – urok93
    Commented Aug 24, 2012 at 8:03

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.