
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, you can definitely create a button that always links to your most recent blog post! Here's how to approach this:
You'll want to write a GROQ query that fetches blog posts, sorts them by date, and grabs the first one. Here's an example:
*[_type == "blog"] | order(publishedAt desc)[0]This query:
_type == "blog"order() function to sort by publishedAt in descending order (most recent first)[0] to grab just the first item (index 0)Once you have the most recent post, you can use its slug field to create your link. Here's a more complete query that projects just what you need:
*[_type == "blog"] | order(publishedAt desc)[0]{
"slug": slug.current,
title
}Then in your frontend code (using Next.js as an example):
import Link from 'next/link'
import { client } from '@/sanity/lib/client'
async function LatestBlogButton() {
const latestPost = await client.fetch(
`*[_type == "blog"] | order(publishedAt desc)[0]{ "slug": slug.current }`
)
return (
<Link href={`/blog/${latestPost.slug}`}>
View Latest Post
</Link>
)
}publishedAt or _createdAt) to sort by[0] array indexing syntax grabs the first element after sorting_createdAt which is automatically added to all documentsThis is a common pattern in Sanity and works great for "Latest Post" links, featured content, and similar use cases!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store