tags:

views:

29

answers:

1

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.

+3  A: 

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 :/

Henrik Opel
That will do, thanks a lot for both the snippet and the clarification on the returned results from taxonomy_select_nodes()
JoseMarmolejos