内容丰富:如何查询附加了任一条目的条目?
Contentful: how to query entries that have one of either entries attached?
我正在尝试根据 2 个或更多类别过滤博客 post。
博客 post 是一种内容类型,类别也是。每个博客 post 只能有一个类别。该类别通过引用字段连接到 post。我希望用户能够过滤 posts。用户可以一次 select 多个类别。
看来我无法编造查询。这是我目前所拥有的:
// 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) 的引用的博客 post。但是,使用此查询不会返回任何条目。我正在使用 contentful/laravel v4.0.
好的,我明白了。我正在使用 Contentful Core v2。 v2 的正确查询结构如下:
// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
->setContentType('blogPosts')
->where('fields.postCategory.sys.id[in]', $categories);
我正在尝试根据 2 个或更多类别过滤博客 post。
博客 post 是一种内容类型,类别也是。每个博客 post 只能有一个类别。该类别通过引用字段连接到 post。我希望用户能够过滤 posts。用户可以一次 select 多个类别。
看来我无法编造查询。这是我目前所拥有的:
// 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) 的引用的博客 post。但是,使用此查询不会返回任何条目。我正在使用 contentful/laravel v4.0.
好的,我明白了。我正在使用 Contentful Core v2。 v2 的正确查询结构如下:
// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
->setContentType('blogPosts')
->where('fields.postCategory.sys.id[in]', $categories);