Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to exclude the current person from a query in Sanity.io

2 replies
Last updated: Aug 15, 2023
How do I exclude current 'item' from a query? Need to query all persons except the current person.


export const teamMemberQuery = groq`*[_type == "person" &&  slug.current == $slug][0]{ 
    name,
    _id,
    _ref,
    slug,
    "functionTitle": functionTitle[_key == $language][0].value,
    "bio" : bio[_key == $language][0].value,
    "usps": usps[_key == $language][0].value,
    "tags": tags[_key == $language][0].value,
    image {
					asset->{
						...,
						metadata
					}
				}, 
    "relatedPersons": *[_type == "person" && (person._id != _id) && defined($language)] | order(publishedAt desc) {
      name,
    },
Aug 15, 2023, 11:23 AM
*[_type == "person" && ^._id != _id && defined($language)]

Aug 15, 2023, 11:23 AM
user A
that was quick. Thank you šŸ‘
Aug 15, 2023, 11:24 AM

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?