[wp-trac] [WordPress Trac] #40012: Only add_metadata if no matching value
WordPress Trac
noreply at wordpress.org
Thu Mar 2 02:04:45 UTC 2017
#40012: Only add_metadata if no matching value
--------------------------------+-----------------------------
Reporter: johnjamesjacoby | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: 2.9
Severity: normal | Keywords: 2nd-opinion
Focuses: |
--------------------------------+-----------------------------
`add_metadata()` has a `$unique` parameter, but it only looks for a unique
`meta_key` for the given object ID. I have a need to add meta-data with
the same `meta_key` but different values, and only if that `meta_value`
isn't already present with the same key.
To do this now, requires:
* Getting all meta-data for the ID by `meta_key`
* Checking those array-values for my value
* Bailing if it's already present, or...
* Proceeding with `$unique` set to `false`
It'd be lovely if `add_metadata()` either:
* Accepted strings like `key`, `value` for the `$unique` parameter, to
switch up the check
* Added a second parameter for unique value in addition to a unique key
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40012>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list