Query content relationship in multiple document types

Is there a way to query multiple document types, based on a content relationship?

Looking at this : https://prismic.io/docs/laravel/query-the-api/query-by-content-relationship as a reference, query works for one or the other, but not both.

For example:

[ Predicates::at('my.blog_post.categories.category', 'X2EUvRAAACUAYj3L'),
  Predicates::at('my.resource.categories.category', 'X2EUvRAAACUAYj3L') ]

What’s the best way to query for a custom “category” (in a group), across multiple document types, to get all the documents with that relationship?

Hey @rjessome,

You can query one document type by multiple content relationships, but not multiple document types by multiple content relationships.

In fact it isn’t possible to query documents in multiple types by a content field of any kind.

I’ve added this as a feature request to the tracker, but this is not something that we plan to implement in our current road map. If/when we have any changes in this we’ll update you here.

For now the only way to do this will be to make multiple queries. I know this may cause your site to be slower, but by using a Static Page Generator like Jigsaw for Laravel, Next for React or Nuxt for Vue it shouldn’t be an issue.

Let me know if you have any further questions.


Gotcha, fair enough - not a huge deal to do the queries and stitch them together.

But, yeah would be a great feature to be able to query multiple document types by a content relationship - for things like categories and authors that might be used across different things

1 Like

Yeah, I can definitely see the advantage with that use case.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.