What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Querying Shopify collections with specific metafield using GraphQL

Querying Shopify collections with specific metafield using GraphQL

AdrienDV19
Shopify Partner
1 0 0

I'm currently working on querying Shopify collections using the GraphQL Storefront API. I'm trying to retrieve collections where a specific metafield (filtering_category) has a value of 'Theme'.

Here's the GraphQL query I'm using:

  

{
  collections(
    first: 250
    query: "metafield: { key: 'filtering_category', value: 'Theme' }"
  ) {
    pageInfo {
      startCursor
      hasNextPage
    }
    edges {
      node {
        id
        title
      }
    }
  }
}

However, despite having collections with filtering_category set to 'Theme', the query is not returning any results. Could you please advise if there's anything specific I should check or adjust in my query to ensure it correctly filters based on metafields?

Thank you for your assistance.

Replies 4 (4)

Liam
Community Manager
3108 344 895

On the query line can you try:

 

query: "metafields.namespace_key:'namespace.filtering_category' AND metafields.value:'Theme'"

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ShopifyDevSup
Shopify Staff
1453 238 525

Hi folks 👋 - just following up here. You are correct @Eric-HAN - at the moment, we don't support query filtering for metafields on the Storefront API's collection object. My understanding is that at the moment, the only way to query those values directly on collections themselves is through Liquid: https://community.shopify.com/c/shopify-scripts/get-collections-by-meta-fields-i-want-to-filter-vend...

Definitely understand that this isn't the most ideal though, so I'm going to put through a note up to our developers to consider adding metafield query filtering on collections as a possible feature in a future release. 

I can't guarantee anything on my end, but did just want to confirm that I'll send that feature request up to our developers right away here. 

Thanks for the clarification there - really appreciated!

- Al 
Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

andii_
Visitor
1 0 0

Hi Al 👋,

Thanks for the quick follow-up and for confirming that you'll send the feature request to the developers—much appreciated!

In addition to the request for metafield query filtering on collections, it would be incredibly useful if we could also have a way to filter collections based on specific metafields or similar criteria. This functionality would greatly enhance our ability to create more dynamic and tailored storefront experiences.

Thanks again for your support and for considering this additional request!


Best regards,
Andi

Eric-HAN
Shopify Partner
260 29 27

Hi, there

Based on the doc  . Storefront api only supports 3 fields in query param  not covering metafield.

EricHAN_0-1719977208051.png

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee