All Questions

Tagged with
Filter by
Sorted by
Tagged with
8 votes
1 answer
3k views

How to fill arrays of references in a single query

I have a schema type Page which has an array of blocks: { title: 'Page', name: 'page', type: 'document', fields: [ ... { title: 'Blocks', name: 'blocks', type: '...
Slem's user avatar
  • 128
7 votes
1 answer
3k views

Can't make search query work in Sanity CMS

I am trying to perform a very basic search query with Sanity CMS. This is how the person schema I've created looks like: export default { title: "Person", name: "person", type: "document", ...
user1449456's user avatar
6 votes
1 answer
2k views

How do I make a inner join as a condition in GROQ?

I have a dataset with posts, which might have an array of categories. How do I make a GROQ query that selects all posts with a category with the title "Page"? I would think that I could do something ...
dotnetCarpenter's user avatar
5 votes
2 answers
2k views

Resolve reference in Block Content in Sanity.io

I have the Content Block in Sanity like so: export default { title: "Block Content", name: "blockContent", type: "array", of: [ /// stuff here { title: &...
IActuallyDontKnow's user avatar
3 votes
2 answers
4k views

How to get just the most recent of all documents

In sanity studio you get a nice list of the most recent version of all your documents. If there is a draft you get that, if not, you get the published one. I need the same list for a few filters and ...
cfm's user avatar
  • 196
3 votes
2 answers
7k views

Sanity.io GROQ query for array of objects

I'm learning to code and now I am on the stage of a small pet project with Sanity as a CMS. Long story short, making an API I'm trying to fetch cocktails data with votes for the cocktails. The votes ...
SirMatters's user avatar
3 votes
1 answer
4k views

How do I query referenced document fields within an array of objects in Sanity with GROQ?

I have a document which has an array of objects of which one of the fields is a reference to another document. The following query returns the referenced document _id and _type only, and I need other ...
Anthony's user avatar
  • 337
3 votes
1 answer
723 views

It it possible to truncate text in a groq query?

I'd like to create an excerpt from a (portable) text field. Is this something that is possible? I know I can get the text value back using pt::text(body) and I can get values such as length from that. ...
Designer023's user avatar
  • 1,972
3 votes
3 answers
932 views

Data is not updated after changes in the Sanity Studio

I am quite new to Sanity v3 + Next.js v13. Everything works great on my test site, but I have a problem when I update a document (project) or add a new one in the Sanity Studio – these changes are not ...
podeig's user avatar
  • 2,671
2 votes
2 answers
563 views

How to define NOT is sanity.io structure builder?

I'm trying to filter all products without categories (which is array of references) and can't find how to do it. S.listItem() .title('Without category') .id('productsWithoutCategories') ....
Daria Moreno-Gogoleva's user avatar
2 votes
2 answers
1k views

Sanity GROQ: How do i get drafts for the array of references in a document?

I have a document type page which contains an array of blocks that are the references to other object types. When i fetch the data for page document, it returns draft data for document but not for the ...
Mutahhar Ahmad's user avatar
2 votes
4 answers
3k views

How to filter Sanity posts by category title?

Here what I've done in vision *[_type == "post" && categories == SOCIAL ]{ _id, title } It returned No documents found in dataset production that match query: *[_type == "...
Shaiful Rizal Shaharudin's user avatar
2 votes
1 answer
1k views

Order by random in Sanity.io GROQ query not working?

Sanity.io is awesome! But as I'm just beginning, I cannot find some things yet I know in e.g. MySQL. According to the GROQ cheat sheet I should be able to randomly sort and slice (LIMIT + OFFSET in ...
Jos's user avatar
  • 1,474
2 votes
1 answer
193 views

How to use arithmetic operator to calculate sum

I have a review type with a rating field that contains a number from 1 to 5. Now I'd like to calculate the average rating. Relevant schema: { name: 'rating', title: 'Rating', ...
jgillich's user avatar
  • 73.8k
2 votes
1 answer
857 views

Is it possible to query document schema metadata in Sanity/GROQ?

I have a simple singleton document schema defined in my Sanity/NextJS project, to model my "Colophon" page (richText is a custom block field type): export default { title: 'Colophon', ...
BigglesZX's user avatar
  • 989
2 votes
1 answer
335 views

Is it possible to do geospatial queries in sanity.io?

I found out that sanity supports Geopoint type, but I could not find any information if it's possible to do any filter operation on this type. Are geospatial queries possible?
Vladimír Polák's user avatar
2 votes
0 answers
320 views

POST request to Sanity CMS using Next.js API & next-connect resulting in 500 ERROR

I am having trouble making a POST request of user info on a register form to the Sanity CMS.I am using Next.js & next-connect. I am getting a 500 error when making the request. Here is a snippet ...
Calathea's user avatar
1 vote
3 answers
2k views

Error: Errors while building: ./node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js Module parse failed: Unexpected token (307:11)

Hi everyone hope you all doing good, I am trying to add a plugin to sanity and the plugin is sanity-plugin-order-documents .I have followed all the steps shown in the documentation step by step. I ...
Abdellah Slimani's user avatar
1 vote
1 answer
3k views

How to filter Sanity.io dataset based on a field on references

How to get all posts by a category slug in GROQ? You can see that a post is added to one or more categories. I would like to get all posts by a category slug to show the posts on a category page. I am ...
Ben Jonson's user avatar
1 vote
1 answer
1k views

Sanity.io GROQ: retrieve documents that have a key defined inside array of objects

I have documents that look like this { "_type": "celeb", "name": "foo", "facts: [ {a: 1, topics: {_ref: 'asd', _type: 'reference'}}, {a: 2}, ...
M.K. Safi's user avatar
  • 6,759
1 vote
1 answer
661 views

How to compare arrays in GROQ

I have a blog with sanity CMS and I want to request related posts depending on corresponding tags from the current post which means I have to compare two arrays of tags. My tags are described in post ...
Quentin C's user avatar
  • 337
1 vote
1 answer
890 views

Limit array of references to documents that have not been referenced yet

I have a "reference selector" (i.e. a module where editors can choose documents to reference) but I want to limit the results to the documents that have not been referenced yet. This is the ...
Christoph Berger's user avatar
1 vote
3 answers
2k views

Sanity io show blog posts by author

I'm learning Sanity io CMS and GROQ. I've build a simple blog using one the Sanity predefined blog schema. I've managed to show posts, a single post and the author page, showing name, image and bio. ...
Mauro74's user avatar
  • 4,786
1 vote
1 answer
4k views

Filter query result by field value inside array of objects [Sanity.io & GROQ]

I'm trying to find a product variant inside my list of products(on sanity.io using GROQ), to do so, I have the sku of the variant that I want. The query I'm using is *[_type == "product" && ...
GB5's user avatar
  • 509
1 vote
1 answer
1k views

Sanity GROQ query to not return nullish values

I was querying Sanity with GROQ and wanted to get response excluding nullish values in case there is no image url is available but if it is then return the image url. Doing like this: defined(image) =&...
Suleman Ahmad's user avatar
1 vote
1 answer
3k views

New nextjs 13 next/image component not loading with sanity.io image

I'm trying to get a simple next/image component displaying properly but the images just won't load. I'm using nextjs 13 which was just released so this is a new version of the component. I'm using ...
happycoder2121's user avatar
1 vote
1 answer
2k views

How to use query param as a variable in groq sanity query inside getServerSideprops in next js?

I'm trying to implement search fuctionality in my blog project but facing problem in using variable in groq query(sanity) inside getServersideprops. Here is my code import React from 'react' import { ...
Tejender Kumar's user avatar
1 vote
1 answer
2k views

Can I reach a grandparent from a GROQ query?

I'm trying to run a GROQ query for my Sanity.io project that should filter out child documents that contain references based on a grandparents id. Is it possible to do so? I've come to an ...
cabc's user avatar
  • 35
1 vote
1 answer
808 views

Fetch _id of last created document of given type in Sanity

In Sanity, for a given document type named message, how can I get the _id of the newest message document?
ArneHugo's user avatar
  • 6,250
1 vote
2 answers
235 views

sanity groq not returning queried data

Im having trouble using groq to fetch data. All my other groq queries work expect this one. The data im trying to query works with the sainty groq vs plugin when i manually set the $slug variable but ...
lorenzo washington's user avatar
1 vote
1 answer
738 views

Groq: join to a document field

I have a schema that reads something like this: a Page (document) has an array of Items (object); each Item can have a Post (document); each Post has several Tags (document). I have got most of the ...
Eric_WVGG's user avatar
  • 2,947
1 vote
1 answer
169 views

Unable to Style Sanity Content using BlockContent

guys I need some help regarding styling my sanity content, So the issue is I'm trying to style the code block, but I'm not able to do so, when I style other items like h1, h2, h3, etc. then the code ...
Aryan Srivastava's user avatar
1 vote
1 answer
528 views

How to dynamically create pages using sanity and next js?

I just watched this video on youtube, where we can see that a preview of the page is being instantly dynamically generated within the studio, while the person is adding the components randomly from ...
Rockafella96's user avatar
1 vote
0 answers
41 views

How to find a document in Sanity (groq) that has a value between two numbers

How do you query for a document using GROQ when the document has a value e.g. Width and you want to query for all documents that have a width value between 500 and 700 for example. It seems there isn'...
mylesthe.dev's user avatar
  • 9,615
1 vote
0 answers
140 views

Is using parameters with GROQ injection safe?

After a bit of searching, I didn't find anything definitive. Does anyone know if the following example is safe from injection when using GROQ? const query = '*[_type == 'car' && maker == $...
ptf's user avatar
  • 583
1 vote
0 answers
750 views

API Post request to sanity patch query takes upwards of 2 seconds to complete

I'm struggling to understand what could be causing a slow response from the server, upwards of 2 seconds for a simple patch. I've gone ahead and posted an example to help better illustrate the problem....
askmeaquestion1234's user avatar
1 vote
1 answer
245 views

How to query all images in an array?

I'm using nextjs/Sanity. Want to get all of the image types out of an array, but nothing is showing up and nothing is coming up in the console either. It's particularly everything within the current ...
paparonnie's user avatar
1 vote
1 answer
281 views

Having an issue pulling data from my sanity.io database in react native app. I can pull it in one section but not another

I am having an issue with this code for a bit now. I think the problem is in my useEffect hook with the "{ id: '' }". When I console.log this data from my sanity.io client, the data comes up ...
Matthew Bianco's user avatar
1 vote
1 answer
396 views

Unable to fetch tweets using groq/sanity

I'm doing a code-along for a twitter clone and am not able to get tweets. I'm using Sanity and can confirm the data is there, and is fetched w/o error on sanity client. I think the issue is with groq, ...
AntH00's user avatar
  • 13
1 vote
1 answer
914 views

How to show Referenced Object with Groq

I have a "Success cases" page (/cases) where when I go into the detail page I have something like /cases/some-slug. The "cases" schema is referencing to a Brand, like this: {...
Julio Chamizo's user avatar
1 vote
3 answers
1k views

Generating static pages (0/8)TypeError: Cannot destructure property 'title' of 'post' as it is undefined

I'm developing a blog using nextJS & sanity. And I connected sanity with nextJS and it's perfectly working in development mode. But when I try to deploy in Vercel or build through the VSCode, it ...
Wanuja Ranasinghe's user avatar
0 votes
1 answer
637 views

How to query the next post with GROQ sanity

I want to fetch the data for the next post in order they were created at - currently nextPost returns null `*[_type == "project" && _createdAt > ^._createdAt] | order(_createdAt ...
Burger Sasha's user avatar
0 votes
1 answer
544 views

How to limit query to 3 most recent posts with sanity?

I am trying to query the 3 most recent article posts but not sure how to set the limit "latestArticles": *[_type == "article" && wasDeleted != true && isDraft != ...
Burger Sasha's user avatar
0 votes
1 answer
338 views

How to fetch multiple documents within a single query?

I want to fetch multiple pages within a single query. My code is causing errors const pagesQuery = groq`{ *[_type == 'homepage']{slug}, *[_type == 'faq']{slug}, *[_type == 'contact']{slug} ...
Burger Sasha's user avatar
0 votes
1 answer
767 views

Sanity posts display all categories, not just ones associated with post

I am working on making a blog using React and Sanity, and I want to display the categories associated with each post underneath each post. I am able to display the categories, but it displays all ...
Brandon Pyle's user avatar
0 votes
1 answer
1k views

query by reference sanity.io

I have three schemas docTopics => subTopics => article that are references of each other. I wanted to write a query for docTopics to return all the subTopics references to docTopics export const ...
sep's user avatar
  • 29
0 votes
2 answers
2k views

how to filter only one data with a specific slug in sanity.io?

Data: [ { "name": "Gates of Olympus", "slug": { "_type": "slug", "current": "gates-of-olympus" } }, {...
Sai Krishnadas's user avatar
0 votes
1 answer
503 views

Sanity.io GROQ - Retrive document by highest reference count in other documents

I have a tag document that looks like { name: 'tag', title: 'Tag', type: 'document', fields: [ { name: 'label', title: 'Label', type: 'string', } ] } And page ...
The Unknown's user avatar
0 votes
1 answer
3k views

Sanity.io groq filter inside an array of objects using a reference field

I've been stuck for a while trying to optimise my groq query. I have page content that contains an array objects (different languages). I've been playing around in Sanity Vision to see how I can ...
Tanpo's user avatar
  • 263
0 votes
1 answer
585 views

sanity-algolia get error when using pt::text

I'm trying to integrate algolia search with sanity CMS using the sanity-algolia library (ref https://www.sanity.io/plugins/sanity-algolia) But when i try to get the plain text from Portable Text rich ...
Kim Vu's user avatar
  • 618