Any way to query a group of different document types and then order them by a field name such as "release_date" instead of document.first_publication_date

I have a group of different content types that I am trying to display in chronological order all together. Here’s the page:

Currently, the only way I’m able to order the different content types chronologically together is like this:

@posts = api.query(
      [ Prismic::Predicates.any("document.type", ["analysis", "data_viz", "blog", "news", "report" ]) ],
      {
        "page" => page,
        "pageSize" => (9),
        "orderings" => "[document.first_publication_date desc]"
      }
    )

Each content type has a field called “release_date” that allows the editor to set the “date” of the post. For the individual index pages for each type of content (e.g. news, analysis, blog, etc. I’m able to order them by release date like this:

@posts = api.query(
      [ Prismic::Predicates.any("document.type", ["blog" ]) ],
      {
        "page" => page,
        "pageSize" => 9,
        "orderings" => "[my.blog.release_date desc]",
        "after" => @hero_post_id
      }
    )

But I would like to also order them by release_date on the page that contains all content types (https://bailoutwatch.org/latest).

I tried this:

@posts = api.query(
      [ Prismic::Predicates.any("document.type", ["analysis", "blog", "data_viz", "news", "report" ]) ],
      {
        "pageSize" => 1,
        "page" => 1,
        "orderings" => "[my.analysis.release_date desc, my.blog.release_date desc, my.data_viz.release_date desc, my.news.release_date desc, my.report.release_date desc]",
        "ref" => ref
      }
    )

But, all that does is loop through all of the document types that I list first, display them in chronological order, then goes onto the second document type displays them chronologically, etc.

I’m doing this in Rails. Is my only option to collect all of the documents from each document type in an API call, then manually sort them by “release_date” in Ruby?

Hi @leemc. Unfortunately it isn’t possible to order or sort documents by a field across different Custom Types. This is a duplicate thread and discussed here: