Sort by combination of fields in Javascript API

hi there

i’m querying the api via:

i’m querying the javascript api via:

const queryData = await this.$prismic.api.query(
    [
      this.$prismic.predicates.any('document.type', ['news', 'press'])
    ],
    {
      orderings: '[my.news.date desc, my.press.date desc]',
      pageSize: 100, // max pageSize
      page: pageNumber
    }
  )

press-items and news-items both have a “date” field on them.

the ordering currently orders all results by news.date and THEN by press.date which leads to all the press-results being returned first.

How can I sort all of the results by date? So that the results are a list of news and press-items both sorted by date? Something like “my.any.date”?

Hi @rrkuepper, unfortunately it isn’t possible to order your results by a Date field across different custom types. This is something I would love to see myself, and I’ve added another tick for this in our feature request tracker as a possible improvement for the future.

For now, you’ll need to organize the results in your website app after querying.