🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

When Referencing another Schema, how to Extract the URL from that Referenced Post?

4 replies
Last updated: Jul 20, 2022
Hey everyone, when referencing another schema (
type: "reference"
), how can I extract the URL from that referenced post? At the moment the output only provides me with the _ref and _type, which isn't very useful...

      name: "linkToNews",
      title: "Lien au publication de nouvelles",
        "Créer un lien vers un article de presse contenant plus d'informations sur les dates limites de soumission.",
      type: "reference",
      to: { type: "nouvelles" },
Jul 20, 2022, 2:55 PM
You could expand it using GROQ:
*[_type == 'yourdoc']{ name, linkToNews-> }
see the documentation on joins here: https://www.sanity.io/docs/groq-joins
Jul 20, 2022, 2:59 PM
nice, thanks! That worked and I'm able to query all the data from
, but how would I just extract the
rather than all the data from a given
Jul 20, 2022, 3:07 PM
Cool. Here's what you could do:
*[_type == 'nouvelles']{
  name, 'slug': linkToNews->slug
Jul 20, 2022, 3:10 PM
awesome, cheers!!
Jul 20, 2022, 3:11 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?