Skip to content

Instantly share code, notes, and snippets.

@samuelhorn
Last active October 24, 2023 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelhorn/164e46863c720b8cf9e2bac0a40d3479 to your computer and use it in GitHub Desktop.
Save samuelhorn/164e46863c720b8cf9e2bac0a40d3479 to your computer and use it in GitHub Desktop.
fetch posts related to author
import { createClient } from "@/prismicio";
import { filter } from "@prismicio/client";
const Author = async ({ params }: { params: { uid: string } }) => {
const client = createClient();
// Fetch the actual author
const author = await client.getByUID("blog_author", params.uid)
// Fetch all blog posts related to author
const blogs = await client.getByType("blog", {
filters: [filter.any("my.blog.author", [author.id])],
orderings: [
{
field: "my.blog.date",
direction: "desc",
},
]
});
...
};
export default Author;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment