GROQ query to find all posts with a specific location

205 Views Asked by At

I have set a sanity schema that present a restaurant and the restaurant has an array of locations that accept multiple string(cities) as shown in the picture.

I am asking if there is a way to fetch data from sanity using the location array. so for example I want to return all the restaurants that has "Casablanca" in the location array. just like we use the slug in this example : *[slug.current == "${slug}"] { ..., sections[]{ ..., dishes[]->{ ..., } } }

1

There are 1 best solutions below

0
On

This is the solution I managed to came up with :

 *[_type == "restaurant"] {
   ...,
}[location[] match 'dakhla']