Remi Sture
Frontend lead @ Eviny.no
Remi is located at Kleppestø, Norway
This snippet can be used to fetch current, previous and next articles based on publication date and related tags.
*[_type == $type && slug.current == $slug]{
"current": {
"slug": slug.current, title, publicReleaseDate, "tags": tags[]->tag
},
"previous": *[_type == $type && count((tags[]->tag)[@ in ^.^.tags[]->tag]) > 0 && ^.publicReleaseDate > publicReleaseDate]|order(publicReleaseDate desc)[0]{
"slug": slug.current, title, publicReleaseDate, "tags": tags[]->tag
},
"next": *[_type == $type && count((tags[]->tag)[@ in ^.^.tags[]->tag]) > 0 && ^.publicReleaseDate < publicReleaseDate]|order(publicReleaseDate asc)[0]{
"slug": slug.current, title, publicReleaseDate, "tags": tags[]->tag
},
}|order(publicReleaseDate)[0]
{
type: "news_article",
slug: "my-article-slug",
}
{
"current": {
"slug": "current-article",
"title": "Current article"
"publicReleaseDate": "2022-09-22",
"tags": ["news"],
},
"next": {
"slug": "next-article",
"title": "Next article"
"publicReleaseDate": "2022-10-11",
"tags": ["news"],
},
"previous": {
"slug": "previous-article",
"title": "Previous article"
"publicReleaseDate": "2022-08-31",
"tags": ["news"],
}
}
Inspired by this snippet by Knut Melvær.
Frontend lead @ Eviny.no
Runs Support @ Sanity.io
Support Engineer at Sanity.io
Ever wondered where and if your content types are used?
Go to Search for object types across document typesIf you'd like to be able to reference your project users within your content, you'll need to create a document for them.
Go to Create A Document for All Current Project UsersScript to batch remove a field from all documents that match a GROQ query
Go to Batch remove a fieldA custom input component that lets the schema creator control max, min, and step values on a number input.
Go to Controlled Number Custom Input Component