Unlock seamless workflows and faster delivery with our latest releases – get the details

Search for object types across document types

By Remi Sture

Ever wondered where and if your content types are used?

GROQ

*[_type in $documentTypes && language in $languages && count(sections[_type in $objectTypes]) > 0]{
    _type,
    "lang": language,
    "slug": language + "/" + slug.current,
    "sections": sections[_type in $objectTypes]{
      _type, 
      "name": coalesce(title, name, heading),
      "content": coalesce(pt::text(content), pt::text(lead)),
    },
    "hits": count(sections[_type in $objectTypes])
} | order(hits desc, slug asc)[$limitStart...$limitEnd]

Params

{
  documentTypes: ['page', 'article'],
  languages: ['nb', 'en'],
  objectTypes: ['map', 'accordion'],
  limitStart: 0,
  limitEnd: 10,
}

Example result

[
    {
      "_type": "page",
      "hits": 4,
      "lang": "nb",
      "sections": [
        {
          "_type": "accordion",
          "content": "Content 1",
          "name": "Name 1"
        },
        {
          "_type": "accordion",
          "content": "Content 2",
          "name": "Name 2"
        },
        {
          "_type": "map",
          "content": "Content 3",
          "name": "Name 3"
        },
        {
          "_type": "accordion",
          "content": "Content 4",
          "name": "Name 4"
        },
      ],
      "slug": "nb/my-slug-1"
    },
    {
      "_type": "article",
      "hits": 2,
      "lang": "en",
      "sections": [
        {
          "_type": "map",
          "content": "Content 5",
          "name": "Name 5"
        },
        {
          "_type": "accordion",
          "content": "Content 6",
          "name": "Name 6"
        },
      ],
      "slug": "en/my-slug-2"
    }
  ]

Contributor

Other schemas by author