Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Adding validation for featured content and sorting an array by date in Sanity schema.

3 replies
Last updated: Dec 10, 2021
Hello there, i have a schema in which a field of
contain named as isFeatured. Now i want to do validation like if isFeatured is true in any doument, i shouldn't be able to make isFeatured true in any other document and it should show which document has already isFeatured true. How to add this kinda validation. Thanks.
Dec 9, 2021, 9:48 AM
Would be better to use a reference to the featured item from the content type on which another appears as featured? For example, if you wanted to feature a blog post on the home page, the home page would have a field for FeaturedItem where the content manager could select the appropriate blog post as a reference.
This is how i approach featured content 95% of the time. It saves on maintenance because you only have to go to one place to select the new featured item and you lose the risk that people will select too many items as featured.
Dec 9, 2021, 3:09 PM
user J
Thanks for your response, another thing i want to ask is that i have an array of object and i want to order by
which is a value in objects. I am unable to write query for it.
Here's the structure,







"newsBlockTitle":"News Cards for Home Page"





"articleDescription":*[*...*]*_1 item_




"headline":"The NRP Group Breaks Ground on a Record 21 Multifamily Apartment Communities in 2020"


"selectedCategory":*{*...*}*_2 items_

"slug":*{*...*}*_2 items_

"subHeadline":"The NRP Group subheading"






Dec 10, 2021, 8:09 AM
Hi Mohammad. You can sort your array using the
function. There are some details here but if you want to post your schema we can probably show you where you’d add it.
Dec 10, 2021, 10:09 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?