最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Searching on multiple reference fields in contentful - Stack Overflow

programmeradmin2浏览0评论

I am trying to figure out how to retrieve specific articles based on author (reference), my current function retrieves all articles, but I only want the author specific ones

 const resp = yield client.getEntries({
  'fields.insightsArticle': true,
  'fields.excludeCountries[nin]': country,
  'fields.publicationDate[lte]': moment(new Date()).toISOString(),
  'fields.author.fields.firstname': author.firstName,
  'fields.author.fields.lastname': author.lastName,
  content_type: 'insight',
  include: 2,
  order: '-fields.publicationDate',
  limit,
  locale,
});

The current log I am getting from contentful is: "When searching on references you must specify the Content Type of the reference. Please send a Content Type id as a query parameter"

I get that, since I am defining the content type as insight.

Any suggestions are wele!

I am trying to figure out how to retrieve specific articles based on author (reference), my current function retrieves all articles, but I only want the author specific ones

 const resp = yield client.getEntries({
  'fields.insightsArticle': true,
  'fields.excludeCountries[nin]': country,
  'fields.publicationDate[lte]': moment(new Date()).toISOString(),
  'fields.author.fields.firstname': author.firstName,
  'fields.author.fields.lastname': author.lastName,
  content_type: 'insight',
  include: 2,
  order: '-fields.publicationDate',
  limit,
  locale,
});

The current log I am getting from contentful is: "When searching on references you must specify the Content Type of the reference. Please send a Content Type id as a query parameter"

I get that, since I am defining the content type as insight.

Any suggestions are wele!

Share Improve this question asked Jul 9, 2019 at 11:49 Bram WesselinkBram Wesselink 1471 gold badge1 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

i had the same problem! you can specify the content type of the reference by adding:

'fields.author.sys.contentType.sys.id': 'author'

also, i would move the content_type: 'insight' line as the first entry and remove limit and locale since you're not using those fields.

发布评论

评论列表(0)

  1. 暂无评论