views:

71

answers:

2

Hi,

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.

+1  A: 

This query will get the term ids for you.

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

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

related questions