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.

Filtering products from collection by tag with Storefront API

Solved

Filtering products from collection by tag with Storefront API

lukebennett
Shopify Partner
8 1 1

I'm building a Shopify store using the Storefront API.
I noticed that in the most recent version of the API (2023-01) there is now support to filter products in a collection by tag. I need to filter by tag so I can show ladies or mens products, so this feature is very useful for me.
However it doesn't seem to be working.

When I run this query:

query {
  collection(handle: "greg-norman") {
    title
    products(first: 30, filters: { tag: "Mens" }) {
      nodes {
        title
        vendor
        tags
      }
    }
  }
}

I get back this data:

{
  "data": {
    "collection": {
      "title": "Greg Norman",
      "products": {
        "nodes": [
          {
            "title": "Greg Norman Polo Umbrella Coral Guava",
            "vendor": "Greg Norman",
            "tags": ["G2S22K469", "Ladies", "Polo"]
          }
          // omitted for brevity
        ]
      }
    }
  }
}

As you can see, the first product returned, doesn't actually match the tag that I'm filtering by. Any idea if I'm doing something wrong here?

 
Accepted Solution (1)

lukebennett
Shopify Partner
8 1 1

This is an accepted solution.

I found a solution:
https://github.com/Shopify/hydrogen/discussions/490

 

TLDR: you need to install the "Search and Discovery" app, and enable searching by tags from there.

View solution in original post

Replies 3 (3)

Ericcwong
Shopify Partner
2 0 1

I saw that they added it too but it seems work on the newer version 2023-04 but my problem is how to query more than one tag? I tried to use AND or to separate them with commas and that didn't work.

Jaybox325
Shopify Partner
2 0 0

Did you ever get a response to this? I'm looking to filter tags with the OR method.

lukebennett
Shopify Partner
8 1 1

This is an accepted solution.

I found a solution:
https://github.com/Shopify/hydrogen/discussions/490

 

TLDR: you need to install the "Search and Discovery" app, and enable searching by tags from there.