How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Using localized bodyPortableText with coalescing in GROQ query

4 repliesLast updated: Nov 29, 2025

Hi! I’m having trouble using a localized bodyPortableText in query. I used the
localeString
example but switched the used type from
string
to
bodyPortableText
. How do I now combine the use of language parameter, coalescing and expanding the array content of the
bodyPortableText
in the projection? 😬
AI Update

I understand you're having trouble querying a localized bodyPortableText field where you need to combine a language parameter, coalescing, and expanding the array content.

The key is understanding that with localized arrays (like when using the internationalized-array plugin), you need to:

Here's the pattern:

*[_type == "yourDocType"] {
  title,
  "body": coalesce(
    bodyPortableText[_key == $language][0].value[],
    bodyPortableText[_key == $baseLanguage][0].value[],
    []
  )
}

Breaking this down:

Without the []: You'd get the Portable Text as a nested structure rather than expanded content.

With the []: You get the actual block content that you can render.

If you need to transform the Portable Text blocks themselves, you can project inside the expansion:

"body": coalesce(
  bodyPortableText[_key == $language][0].value[]{
    ...,
    _type == "image" => {
      ...,
      asset->
    }
  },
  bodyPortableText[_key == $baseLanguage][0].value[],
  []
)

This pattern is covered in the Sanity localization documentation, specifically in the "Querying localized arrays with GROQ" section. The same principles apply whether you're working with simple strings or complex Portable Text content - the [] expansion is what makes it work for arrays within arrays.

Show original thread
4 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions