Skip to main content

Query by metafield value

It's possible to query Shopify resources by metafield value. This is useful if you want to find all products or metaobjects that have a metafield with a specific value.

To query by metafield value, first the metafield you want to query by must have filtering enabled.

Filtering can also be enabled in the Shopify admin. Learn more about enabling filtering for product metafields and filtering for metaobject fields.

Available metafield types include:

  • Single line text or Single line text (list)
  • Product reference or Product reference (list)
  • True or false
  • Collection reference or Collection reference (list)
  • Page reference or Page reference (list)
  • Metaobject reference or Metaobject reference (list)
  • Company reference or Company reference (list)
Note

Only case-sensitive, exact matches are supported for filtering.

Anchor to Querying metaobjects by field valueQuerying metaobjects by field value

Anchor to Querying metaobjects by taxonomy reference field valueQuerying metaobjects by taxonomy reference field value

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL mutation

query Metaobjects {
metaobjects(first: 20, type: "shopify--color-pattern",
query: "fields.taxonomy_reference:\"gid://shopify/TaxonomyValue/2\"") {
edges {
node {
id
displayName
type
name: field{key: "color_taxonomy_reference"} { value }
updatedAt
createdAt
}
}
}
}
Note

This example uses the GID structure for the taxonomy node for the color blue. You can find GIDs for taxonomy nodes in the open source Taxonomy Explorer.

Anchor to Querying metaobjects using a simple single line text fieldQuerying metaobjects using a simple single line text field

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL mutation

query Metaobjects {
metaobjects(first: 20, type: "custom--product-feature",
query: "fields.feature_name:\"waterproof\"") {
edges {
node {
id
displayName
type
name: field(key: "feature_name") { value }
updatedAt
createdAt
}
}
}
}
Note

The syntax for querying fields on metaobjects is fields.{key}:{query_value}.

Anchor to Querying products by field valueQuerying products by field value

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL mutation

query Products {
products(first: 20, query: "metafields.custom.material:\"cotton\"") {
edges {
node {
id
title
metafield(namespace: "custom", key: "material") {
value
}
updatedAt
createdAt
}
}
}
}
Note

The syntax for metafields on core resources (such as products) is metafields.{namespace}.{key}:{query_value}.


Was this page helpful?