Fix for Select vocab by name.

  1. /**
  2.  * Utility function to select a vocabulary by name rather than vid.
  3.  *
  4.  * @param $name
  5.  *   The name of the vocabulary to retrieve.
  6.  *
  7.  * @return
  8.  *   The $vid of the vocabulary name referenced, or false if not found.
  9.  */
  10. function _get_vocab_by_name($name) {
  11.   $query = 'SELECT vocabulary.vid AS vocabulary_id FROM vocabulary WHERE vocabulary.name= "%s" LIMIT 1';
  12.   $vocab_id = false;
  13.   $result = db_query($query, $name);
  14.  
  15.   while ($r = db_fetch_object($result)) {
  16.     $vocab_id = $r->vocabulary_id;
  17.   }
  18.  
  19.   return $vocab_id;
  20. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.