Skip to main content
Fetch Single Post

How to fetch a blog post by slug

Updated over 9 months ago

In this guide, we'll discuss how to fetch a single publication post using its slug


To achieve fetching a single post, we'll make the publication query, while using the post object field, which requires the slug argument.

The slug is the last part of your blog URL address that serves as a unique identifier of the page. For example from this blog URL https://blog.favouritejome.dev/why-learn-nextjs-if-i-already-know-reactjs the slug is why-learn-nextjs-if-i-already-know-reactjs

Here's an example query:

query SinglePublicationPost(
$host: String,
) {
publication(
host: $host,
) {
id
title
displayTitle
author {
username
name
}
post(slug: "why-learn-nextjs-if-i-already-know-reactjs") {
title
url
brief
}
}
}

Notice only the post content with the slug why-learn-nextjs-if-i-already-know-reactjs

is retrieved

If you'd like to view all the available fields for the post field please visit the documentation

Next Articles:

Did this answer your question?