Opened 15 years ago
Closed 15 years ago
#11929 closed enhancement (duplicate)
Query objects by metadata
Reported by: | wnorris | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
The new metadata API makes it very easy to get metadata for a known object. For example, operations like "Give me the last name for the user #12", or "show me all email addresses that are subscribed to comments on post #4".
However, it does not provide an easy way to look up objects based on metadata keys or values. For example, things like "show me all posts the email address 'foo@…' is subscribed to receive comments for". Or "show me all posts that have a 'mood' custom value set, regardless of value". Or (my personal itch), "what user is associated with the OpenID 'http://foo.com'?"
This kind of querying ability would be immensely useful to plugin authors.
Attachments (1)
Change History (7)
#2
@
15 years ago
(and I haven't bothered formatting this as an actual patch for now, but I will later. I'd like to hear other people's thoughts on it first.)
#3
@
15 years ago
It would be a lot easier to follow your proposal if you did submit it as a patch. See how it's done here.
Here is my first stab at this functionality. It returns an array of objects of the specified meta_type that have the specified meta_key/meta_value pair. If the value is not specified, it returns objects that have any value for the specified key.
Retrieving the object IDs is simple. But is that enough? It still leaves additional work to the plugin author to actually retrieve the object with the specified ID. I went ahead and added one mechanism for populating the objects themselves using a new filter. It would work fine in the case where only a few objects are returned from the query, or where they are already in the WP cache. However, if a large number of objects are returned that are not in the cache, the performance is a bit less than optimal, since each object is populated individually. I'm not sure how much of a concern that should be.