开发者

algorithm to get result like taxonomy_get_tree(). But retrieve only non empty terms

I need to get an associated array of terms in drupal that has node associated with it. However, I can't seem to figure it out the appropriate algorithm.

What I want is something like开发者_运维百科 taxonomy_get_tree(). But, only term that has associated node with it.


This query will get the term ids for you.

db_query("SELECT DISTINCT tid FROM {term_node}");


The following code should do exactly what you're after.

$terms = array();
$result = db_query("SELECT * FROM {term_data} WHERE tid IN (SELECT DISTINCT(tid) FROM {term_node})");
while($term = db_fetch_object($result)) {
  $terms[] = $term;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜