Ticket #7018 (closed defect (bug): fixed)

Opened 8 months ago

Last modified 8 months ago

update_post_meta should add nonexistent values

Reported by: filosofo Assigned to: anonymous
Priority: normal Milestone: 2.6
Component: General Version: 2.5
Severity: normal Keywords: update_post_meta
Cc: filosofo

Description

Currently, if you try to use update_post_meta to update a post meta key and value that don't exist, it just returns false. This behavior is at odds with that of other update functions such as update_option, update_user_option, update_usermeta, wp_update_user, wp_update_category, and update_recently_edited, all of which will create the updated object, if it doesn't already exist.

The other updating functions, which like update_post_meta fail when the object doesn't already exist, would not typically be called when one is agnostic about the existence of the object in question: wp_update_comment and update_attached_file, e.g.; wp_update_term seems to be a possible exception.

Because update_post_meta is semantically similar to update_option and update_usermeta and like them is frequently employed in plugins, it should behave similarly.

Attachments

update_post_meta.diff (2.1 kB) - added by filosofo on 05/21/08 23:51:16.
update_post_meta_efficiency.diff (1.5 kB) - added by filosofo on 05/22/08 01:26:43.
uploads-meta.patch (0.9 kB) - added by azaozz on 05/27/08 06:23:22.

Change History

05/21/08 23:51:16 changed by filosofo

  • attachment update_post_meta.diff added.

05/22/08 00:01:01 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [7978]) Add non-existent values instead of returning g false in update_post_meta(). Props filosofo. fixes #7018

05/22/08 00:09:16 changed by mdawaffe

  • status changed from closed to reopened.
  • resolution deleted.

update_meta() is now double escaping the meta_value.

$wpdb->update( does escaping for you; you don't need to call $wpdb->escape() first.

05/22/08 00:12:19 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7980]) Don't double escape. fixes #7018

05/22/08 01:26:43 changed by filosofo

  • attachment update_post_meta_efficiency.diff added.

05/22/08 01:28:32 changed by filosofo

I've added a patch that removes now-unnecessary checks for the existence of post meta data.

05/22/08 04:42:01 changed by lloydbudd

  • status changed from closed to reopened.
  • version set to 2.5.
  • resolution deleted.

05/22/08 16:33:06 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7985]) Remove unnecessary checks for the existence of post meta data. Props filosofo. fixes #7018

05/27/08 06:22:56 changed by azaozz

  • status changed from closed to reopened.
  • resolution deleted.

Using update_post_meta() instead of add_post_meta() converts the array of attachment properties to a string when uploading new image. That results in php warnings on the Media Library page.

The patch slightly optimizes update_post_meta() and ensures it calls add_post_meta() when the key doesn't exist.

05/27/08 06:23:22 changed by azaozz

  • attachment uploads-meta.patch added.

05/27/08 11:33:11 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7995]) Fix serialization when adding meta via update_post_meta(). Props azaozz. fixes #7018