Prismic.api.query with predicates and ordering

Hey, currently I'm fetching articles data by prismic.api.query(), however, I have no idea how I could add ordering parameter to that query.

My current code:

const response = <PrismicApiResponse>await $prismic.api.query(
        $prismic.predicates.at('document.type', 'article'),
        {
          lang: i18n.localeProperties.iso,
          page: query?.page ? query.page : 1,
          pageSize: 7,
          fetchLinks: 'author.fullname, author.uid',
          ordering: {
            field: 'document.first_publication_date',
          },
        },
);

When I add the ordering object to that settings I get an error Unknown field ordering . So my question is: How can I combine query with ordering?

Hello @radekwawrzyk

Thanks for reaching out to us.

What version of @prismicio/client are you using? I assume you are using V5 because the query function is available with V5 only. With the V5 version, applying orderings query options should be like that:

But we highly recommend using V6 @prismicio/client. Here is a v6 migration guide:

Let me know if you have any further questions.

Thanks,
Priyanka

Thanks!

@radekwawrzyk You are welcome. Feel free to reach out to us if you have any questions.