如何以编程方式获取带有术语的节点


9

我有词汇和自定义内容类型,其中有字段术语参考。

如何在模块中获取特定术语的所有节点?

像这样吗 这行不通。

$field = field_info_field('field_game');
$results = new EntityFieldQuery;
$results->fieldCondition($field, 'field_game_tid', '5')
  ->execute();

$nids = array();
foreach($results as $result) {
  $nids[] = $result->nid;
}

$nodes = node_load_multiple($nids);

Answers:


13

您要指定先搜索节点(并根据您的内容类型选择节点),然后再按术语进行过滤:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'YOUR_CONTENT_TYPE_HERE')
->fieldCondition('field_game', 'tid', 5);

$result = $query->execute();
$nids = array_keys($result['node']);
$nodes = entity_load('node', $nids);

这是一个类似这样的实体查询的好例子(以及更多的现场条件)


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.