Reputation: 1257
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?
Upvotes: 0
Views: 1123
Reputation: 560
You can use the [in] operator to query for entries with a given tag.
contentful
.getEntries({
content_type: "article",
'fields.tags': "website" , //tag id = website
})
.then(({ items }) => {
console.log(items);
})
.catch(console.error);
Upvotes: 1
Reputation: 3879
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>'
})
Upvotes: 1