首页 > 解决方案 > 在内容中搜索多个参考字段

问题描述

我试图弄清楚如何根据作者(参考)检索特定文章,我当前的函数检索所有文章,但我只想要作者特定的文章

 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,
});

我从内容获得的当前日志是:“在搜索参考资料时,您必须指定参考资料的内容类型。请发送内容类型 ID 作为查询参数”

我明白了,因为我将内容类型定义为洞察力。

欢迎任何建议!

标签: javascriptcontentful

解决方案


我有同样的问题!您可以通过添加来指定引用的内容类型:

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

另外,我会将 content_type: 'insight' 行作为第一个条目并删除限制和语言环境,因为您没有使用这些字段。


推荐阅读