内容丰富:如何查询附有任一条目的条目?

时间:2019-02-15 16:11:00

标签: php api contentful

我正在尝试根据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

1 个答案:

答案 0 :(得分:1)

好的,我知道了。我正在使用Contentful Core v2。 v2的正确查询结构如下:

// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
    ->setContentType('blogPosts')
    ->where('fields.postCategory.sys.id[in]', $categories);
相关问题