使用Drupal API获取与类别术语相关的节点数组

Jos*_*jos 4 php drupal

我有一个简单的一级深层词汇分类法.像Vocabulary-> Term-> Node这样的东西.我想知道的是,如果有一个内置函数来获取与单个术语相关的节点数组,比如taxonomy_select_nodes(),但会返回一个节点数组而不是一个字符串.

Hen*_*pel 7

AFAIK taxonomy_select_nodes()是最接近的一个 - 并且它不返回字符串,而是返回查询资源,所以你可以做你想要的事情:

function yourModule_get_nodes_by_term_id($tid) {
  $nodes = array();
  // NOTE: Will lookup by only one term, and only one level deep here!
  $result = taxonomy_select_nodes(array($tid), 'and', 0, FALSE);
  $items = array(); 
  while ($row = db_fetch_object($result)) {
    $nodes[] = node_load($row->nid);
  }
  return $nodes;
}
Run Code Online (Sandbox Code Playgroud)

但是,对于大量节点,性能可能会非常糟糕: