Querying data for two selected fields/categories with identical options

Hello everyone,

I have some blog posts, which each potentially can have two categories I modeled by selected fields. Let's call them category A and category B. The options for the categories are identical, let's call them x, y and z.

Now I would like to query all my blog posts of category z. But since z can occur in either field A or field B, I would need find an OR which I did not see in my extensive reading of the JavaScript docs yet.

Any pointers to solve this without having to make two requests would be highly appreciated

Hi @developer1 ,

Thanks for posting this question, and welcome to the Prismic community.

I do not think that this is possible with a single query, but let me make sure with a more detailed example.

Let's say you have a blog, with a blog_post Custom Type. You also have a category Custom Type.

On the blog_post type, you have two fields that link to the category type, with one called primary_category and another called secondary_category.

You have the following categories:

[
  {
    name: "Red",
    id: "001"
  },
  {
    name: "Blue",
    id: "002"
  },
  {
    name: "Green",
    id: "003"
  }
]

You want to query all blog_posts that link to the red category from either the primary_category or secondary_category.

The most straightforward way to do this is to do two queries: one query where the primary_category matches 001, and another query where the secondary_category matches 001. Then, merge the responses in your code.

However, it's possible that I misunderstood your use case. If so, please let me know, and we can keep working through it.

Best,
Sam