delete_post_meta()

WordPress Bug: Duplicate post_meta Entries

I just submitted a trac ticket about this:

The update_post_meta() and delete_post_meta() functions don’t know how to deal with post revision IDs. add_post_meta() does, it uses the following block of code to make sure the passed $post_id is a real post, not a revision:

``` if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; ```

This is important because the global $post_id when a post is being saved is for the revision, not the real post. If you pass that to these functions, update_post_meta() and delete_post_meta() will try to update or delete the records related to the revision. When update_post_meta() fails to find any records for the post_id you submitted, it calls add_post_meta(). Each attempt at updating the meta will actually create a new row in the table.

For now I’m checking with wp_is_post_revision() before making any calls to the post_meta functions.

Updated: Mark Jaquith committed the patch less than two hours after I submitted it! I love WP.