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.

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

1 Answer 1

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

 
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.