Skip to content

Instantly share code, notes, and snippets.

@sanguis
Created February 6, 2012 20:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanguis/1754684 to your computer and use it in GitHub Desktop.
Save sanguis/1754684 to your computer and use it in GitHub Desktop.
taxonomy_form_options($machine_name) Drupal 7
<?php
/**
* returns a array for use with #options in a form field
* */
function taxonomy_options_array($machine_name, $all = NULL) {
$v = taxonomy_vocabulary_machine_name_load($machine_name);
if (!empty($all)) {
$options[$all[0]] = $all[1];
}
$terms = taxonomy_get_tree($v->vid);
foreach ($terms as $term) {
$options[$term->tid] = $term->name;
}
return $options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment