0

I have this product structure:

enter image description here

And I would like to query by the uid of toys. However, this query is not working:

const products = await this.$prismic.api.query([
  this.$prismic.predicates.at('my.product.category','toys'
)]

It doesn't work unfortunately.

Riza Khan
  • 2,712
  • 4
  • 18
  • 42

1 Answers1

1

Fairly new to Prismic so this took me a while to figure out. The method is very straightforward:

Once you make a relationship between two types (ie, products and categories), you can use this query to get products by a specific category:

const products = await this.$prismic.api.query(
   this.$prismic.predicates.at('my.product.category', 'category_id')
)

The category id is found in the category document (it looks something like: X_uidsfsdFKHF2). Per the documentation, that is the ONLY way to make this query work. You can't use uid or type.

enter image description here

Riza Khan
  • 2,712
  • 4
  • 18
  • 42