Search code examples
contentfulcontentful-api

Contentful JS API: Query for related articles with similar tags as the currently viewed article ? (article…tagList[])


Overview:

Someone views an article (contenttype : article). This article has a list of tags (contenttype : articletags).

Based on the linked tags in this article, I am trying to do a query for articles which has one or more of the same tags linked to it (call it Related Articles with same tags).

Here is the structure:

let tags = article.items[0].fields.tagsList.map(tag => {
   return tag.fields.navn
})

Which I need to query for articles like this:

contentful.getEntries({content_type: ‘article’}) ???

How can I query for the ids?


Solution

  • I think what you're looking for is the links_to query parameter.

    With this one you can figure out which entries relate to another one.

    client.getEntries({
      links_to_entry: '<entry_id>'
    })