Opened 18 years ago
Closed 18 years ago
#7018 closed defect (bug) (fixed)
update_post_meta should add nonexistent values
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 2.6 | Priority: | normal |
| Severity: | normal | Version: | 2.5 |
| Component: | General | Keywords: | update_post_meta |
| Focuses: | Cc: |
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 (3)
Change History (11)
#2
@
18 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
update_meta() is now double escaping the meta_value.
$wpdb->update( does escaping for you; you don't need to call $wpdb->escape() first.
#4
@
18 years ago
I've added a patch that removes now-unnecessary checks for the existence of post meta data.
#5
@
18 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
- Version set to 2.5
#7
@
18 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
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.
(In [7978]) Add non-existent values instead of returning g false in update_post_meta(). Props filosofo. fixes #7018