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

How to use the Patch Set Function to Set a Slug

4 replies
Last updated: May 30, 2022
Is there a way to use the
function to set a slug? I've made a few attempts, but each time I get complaints about it being a
May 30, 2022, 3:53 PM
You can. A
is an object with a
) and a
value (that’s what you want the slug to be), so you’ll need to make sure to patch the entire object.
May 30, 2022, 4:01 PM
So would that be something like this?

    set: {
      slug: { _type: "slug", current: query },
Or is there a better way?
May 30, 2022, 4:05 PM
I’m not familiar with patch.execute, but I tested the following and it worked:

  .set({slug: {_type: "slug", current: query}})
  .then((updatedDoc) => {
    console.log('Update successful! New document:')
  .catch((err) => {
    console.error('Update failed: ', err.message)
May 30, 2022, 4:13 PM
I'll give that option a look, thank you 🙂
May 30, 2022, 4:15 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?