Nuxt category API Query content relationship

Hi Guys,

I've got a blog article page setup and I want to return articles of a related to the category that the current user is on, in async I have:

const post = (await $prismic.api.getByUID('post', params.uid)).data
const categoryPosts = await $prismic.api.query([
$prismic.predicates.at('document.type', 'post'),
$prismic.predicates.at('my.post.blog_category', 'XtemFBIAACQAN3am')
])
and the return
document: post,
slices: post.body,
related: categoryPosts.results,

categoryPosts is working with the blog_category ID XtemFBIAACQAN3am hardcoded, it will return all blog posts specifcally with the category ID, but I want it to return that ID based main documents selected category so that it would be dynamic.

bog_category is a relationship field set up on the post constrained to the custom type: category

Hi @vorben, if I understand you correctly, then I think you need to so something like this:

const post = (await $prismic.api.getByUID(‘post’, params.uid)).data

const categoryId = post.blog_category.id

const categoryPosts = await $prismic.api.query([
  $prismic.predicates.at(‘document.type’, ‘post’),
  $prismic.predicates.at(‘my.post.blog_category’, categoryId)
])

Give that a try and let me know if you get it working!

Thanks!
That seemed to do the trick.