Help with filtering products by brand in a Sanity.io structure

3 replies
Last updated: Jul 28, 2020
Hey all, can anybody see what is wrong with my structure, I can’t seem to filter the desk to show products by brand

S.list()
      .title('/product')
      .items([
        S.documentTypeListItem('product').title('All products').icon(AllIcon),
        S.listItem()
          .title('Products by brand')
          .child(
            // List out all brands
            S.documentTypeList('brand')
              .title('Products by brand')
              .child((brandId) => S.documentList()
                .schemaType('product')
                .title('Products')
                .filter(
                  '_type == "product" && $brandId in brands[]._ref'
                )
                .params({ brandId }))
          )
      ])
Jul 28, 2020, 7:19 AM
It’s already showing the brands but not the products inside each of these brands, correct? Have you tried replacing
&& $brandId in brands[]._ref
with
&& references($brandId)
?
Jul 28, 2020, 7:31 AM
It’s already showing the brands but not the products inside each of these brands, correct? Have you tried replacing
&& $brandId in brands[]._ref
with
&& references($brandId)
?
Jul 28, 2020, 7:31 AM
thank you
Jul 28, 2020, 7:33 AM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?