Storefront API get products with tags and part of a collection

Solved

Storefront API get products with tags and part of a collection

hugoShop
Shopify Partner
4 1 2

Im looking for a way to filter products within a collection based on tags.

 

Basically I want to query this:

collectionByHandle(handle: "latest-stuff") {
    products(first: 10, query: "tag:Blouse") {
      nodes {
        handle
      }
    }
  }

 

But you can't use query inside collectionByHandle. Anyone could help me with a solution?

Accepted Solution (1)

hugoShop
Shopify Partner
4 1 2

This is an accepted solution.

So I found out it's not possible to filter products within a collection based on tags.

 

What you can do is to filter with metafields. My solution was to create a custom metafield for tags, then query something like this:

 

 

collectionByHandle(handle: "latest-stuff") {
    products(
      first: 10
      filters: {productMetafield: {namespace: "filters", key: "tags", value: "Blouse"}}
    ) {
      nodes {
        handle
      }
    }  
}

 

 

View solution in original post

Reply 1 (1)

hugoShop
Shopify Partner
4 1 2

This is an accepted solution.

So I found out it's not possible to filter products within a collection based on tags.

 

What you can do is to filter with metafields. My solution was to create a custom metafield for tags, then query something like this:

 

 

collectionByHandle(handle: "latest-stuff") {
    products(
      first: 10
      filters: {productMetafield: {namespace: "filters", key: "tags", value: "Blouse"}}
    ) {
      nodes {
        handle
      }
    }  
}