我正在尝试根据2个或更多类别过滤博客帖子。
博客文章是内容类型,类别也是如此。每篇博文都只能有一个类别。该类别通过参考字段连接到帖子。我希望用户能够过滤帖子。用户可以一次选择多个类别。
好像我无法编造查询。这是我到目前为止所拥有的:
// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
->setContentType('blogPosts')
->where('fields.postCategory.sys.id', $categories, 'in'); // using 'all' instead of 'in' also doesn't return any results
在我看来,这应该得到所有博客帖子,其中包含对类别条目(id)的引用。但是,使用此查询不返回任何条目。我正在使用contentful/laravel v4.0。
好的,我明白了。我正在使用Contentful Core v2。 v2的正确查询结构如下:
// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
->setContentType('blogPosts')
->where('fields.postCategory.sys.id[in]', $categories);