Contentful logo

Contentful Community

Filtering all Entries of Content Type Post which have the same Linked Reference to Content Type Category as the current Posts Category

Hello i have following problem. I have a post single page where i want to show other related articles from the same category, except the one article on which the user currently is on, in a sidebar. So filtering out the current article isn´t a problem but filtering the posts for the category of the current post is where i got stuck.

what i tried so far was

  const contents = await this.client.getEntries<IBlogPostFields>({
    content_type: ContentTypes.BlogPost,
    locale,
    include: 1,
    limit,
    skip,
    "fields.slug[nin]": filters?.currentPost?.fields?.slug,
    fields: {
      category: [
        {
          fields: {
            slug: filters?.currentPost?.fields?.category?.[0]?.fields?.slug,
          },
        },
      ],
    },
    order: "sys.createdAt",
  });

and this.

  const contents = await this.client.getEntries<IBlogPostFields>({
    content_type: ContentTypes.BlogPost,
    locale,
    include: 1,
    limit,
    skip,
    "fields.slug[nin]": filters?.currentPost?.fields?.slug,
    "fields.category[0].fields.slug": filters?.currentPost?.fields?.category?.[0]?.fields?.slug,
    order: "sys.createdAt",
  });

in both cases the return is is empty but there should be two posts which have the same category than the current one