Opened 14 years ago
Closed 14 years ago
#15049 closed enhancement (duplicate)
postavoid add_metadata to insert duplicated entries
Reported by: | leogermani | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | Database | Keywords: | metadata, post_meta, user_meta |
Focuses: | Cc: |
Description
when calling add_metadata, check if there is already an entry with the same object id, meta_key, and meta_value. If there is, return false so we dont have duplicated entries.
The unique paramater of the add_metadata does not handle with that, since it only cares about the meta_key not beeing duplicated.
When playing with multiple metadatas with the same meta_key, very often you have to check if a value already exists before adding it. I beleive add_metadata should handle it automatically.
Attachments (1)
Change History (6)
#1
@
14 years ago
When used as so you're expecting WP to store array values as separate meta entries. If you store, say, the tag ids a post had across revisions, each serialized as a meta value, and then add and remove a tag, you'd expect a dup entry in there.
Whether WP should discard duplicate meta key/value pairs should be left to plugin authors imo.
#2
follow-up:
↓ 3
@
14 years ago
In your example, the value would have something to relate with the post revision id, wouldn't it? then it would be different...
What could be a problem though is that there may be some plugins/themes that rely on this "feature" and will break
#3
in reply to:
↑ 2
@
14 years ago
Replying to leogermani:
My intent was merely to highlight that there can be a use for arrays that hold the same value multiple times. I've never used it myself but there might be someone out there who does if it works as expected.
If storing identical key/value pairs currently works as expected, I'd recommend wontfix. (It can't be that hard to call in_array() before adding a meta.) If it doesn't, might as well do make WP do the check indeed.
patch for add_metadata function