我有一个Drupal 8内容实体,与一个允许多个值的分类术语相关。我想查询实体并获取仅包含我在查询中使用的术语的内容。问题是我找不到一种方法来查询具有多个分类术语的实体并获取与它们相关的内容。
我的内容实体(节点束)称为“鸡尾酒”,除其他外,还有一个实体参考字段,称为“ field_ingredients”,该字段与分类词汇“成分”有关。我想获得一个实体,该实体具有例如2种具有分类法ID的成分:40和35。
$query = \Drupal::entityQuery('node');
$query->condition('type', 'cocktails');
$query->condition('field_ingredients.entity.tid', 40);
$query->condition('field_ingredients.entity.tid', 35);
$node_ids = $query->execute();
Run Code Online (Sandbox Code Playgroud)
$ node_ids为0
还有这个:
$query = \Drupal::entityQuery('node');
$query->condition('type', 'cocktails');
$query->condition('field_ingredients.entity.tid', array(40, 35), 'IN');
$node_ids = $query->execute();
Run Code Online (Sandbox Code Playgroud)
$ node_ids为3,它返回具有两个分类法ID(或逻辑)之一的节点ID,
正确的答案应该是一个节点ID,这是与两个分类法ID(包含两种成分的混合物)相关的节点