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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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 :/