Fetching a draft post by slug #4535
-
I'm in the process of implementing preview mode with Next.js 13, and I'm not sure how to go about fetching a post that it's in draft mode. It all works fine when the post is published, but that seems to defeat the purpose of preview mode. This is the query I'm using:
How would I adapt this to fetch the post when it's in unpublished? Many thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey there @sebpowell! 👋 You can include/exclude drafts by filtering with the drafts path. Here's all posts without drafts: Here's only the drafts: ➡️ Have a look here for more information: https://www.sanity.io/docs/drafts#ebfb408fa9b6 Cheers! |
Beta Was this translation helpful? Give feedback.
Hey there @sebpowell! 👋
You can include/exclude drafts by filtering with the drafts path.
Here's all posts without drafts:
*[_type == "post" && !(_id in path('drafts.**'))]
Here's only the drafts:
*[_type == "post" && (_id in path('drafts.**'))]
➡️ Have a look here for more information: https://www.sanity.io/docs/drafts#ebfb408fa9b6
Cheers!