How to fetch data via relaitonship field condiiton

So i have 2 custom types

  • authors
    --- name
    --- slug
    --- picture

  • posts
    --- slug
    --- title
    --- content
    --- author linked with author field above

I want all the posts by author id / slug

useAllPrismicDocumentsByType('posts', {
    predicates: [predicate.at('my.posts.author.slug', 'testing-user')],
  });

this is what I am trying to use but getting an undefined

if I try with

predicates: [predicate.has('my.posts.author')],

I am getting all docs in array but if I do .uid or .slug at end I again get undefined

predicates: [predicate.has('my.posts.author.uid')],

How can I match the query so posts.author.slug === 'testing-user' ?

thanks :slight_smile:

Hello @mahir.asrani

Welcome to the Prismic community, and thanks for reaching out to us.

To get all the posts by author, you can do a query by Content Relationship. Here's the documentation for how to do that with JavaScript and the Rest API .

To query by Content Relationship, you need the document ID of the author, so you need to make two queries: one to get the author's ID and then one to get all of the posts that link to that ID.

I hope it answers your questions, and let me know if you have any further questions.