开发者

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

开发者 https://www.devze.com 2022-12-19 21:01 出处:网络
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.

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

精彩评论

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

关注公众号