1

I have a block that displays an imagemap, and each map area represents a taxonomy term. All terms are in the same vocabulary.

For each map area, I know the term name and want to pull the term description using a Drupal function. I know I can do something like this:

<?php $myTerm = taxonomy_get_term_by_name('1'); ?>
<area shape="poly" title="<?php echo $myTerm[0]->description; ?>" coords="1,2,3" href="link2" />

But it's quite clunky and means making a function call for every map area.

Is there an API function that gets every term in a vocabulary (like taxonomy_node_get_terms_by_vocabulary() but without referencing a node?)...

Or should I make a module for this..?

1

I think you could use taxonomy_get_tree or just write your own query_function with the following query: db_query('SELECT description FROM {term_data} where vid = %s',$vid).

1

Unfortunately there isn't an API function for that. You can get the terms with an EntityFieldQuery, and you can wrap it in a function for convenience:

function taxonomy_term_get_by_vid($vid) {
  $query = new EntityFieldQuery();
  $result = $query
  ->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', (int) $vid, '=')
  ->execute();
  return $result['taxonomy_term'];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.