Delete custom fields when deleting posts

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?

Related posts

Leave a Reply

1 comment

  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.