Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/65660479/prismic-query-query-by-category

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
642 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...