Getting an array of nodes related to a category te

2019-05-07 04:29发布

I have a simple one level deep vocabulary taxonomy. Something like Vocabulary->Term->Node. What I want to know is if there's a built in function to get an array of nodes related to a single term, something like taxonomy_select_nodes() but that would return an array of nodes instead of a string.

标签: php drupal
1条回答
Viruses.
2楼-- · 2019-05-07 05:28

AFAIK, taxonomy_select_nodes() is the closest one available - and it does not return a string, but a query resource, so you could do what you want somewhat like so:

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;
}

The performance could get pretty bad for large numbers of nodes, though :/

查看更多
登录 后发表回答