📣 Note: To fetch and filter by meta values, their meta keys must be added to the allowlist.
We can retrieve meta values for custom posts, users, comments, and taxonomies (tags and categories), by querying fields
metaValue (for a single value) and
metaValues (for an array of values) from the corresponding type:
These are examples of queries to fetch meta data, and filter results by meta.
Fetch single meta value
_thumbnail_id from posts:
Fetch array meta value
upvotes from comments:
Custom posts, comments, users and taxonomies (tags and categories) can also be filtered by meta, using the
This input offers an enhancement over how the
meta_query args are provided (to functions
get_users, etc), in that type validations are strictly enforced in the GraphQL schema, and only the combinations that make sense are exposed.
This is accomplished by using the "oneof" input field
compareBy, which offers 4 possibilities. Depending on the chosen option, different operators can be used for the comparison:
In addition, when comparing by
key, there's no need to provide input
We can pass several items under
metaQuery, and decide if to do an
OR of their conditions by passing input
relation on the first item in the list.
This query filters posts where meta key
This query filters users where meta
nickname has a certain value:
This query filters comments where meta
upvotes (which is an array of integers) has either values