7 – How can I get all parent taxonomy terms to use to alter a view?


The taxonomy has depth but I would like, if the hierarchy is fruit>apple>red delicious that when I use $topic_options hook_views_query_alter, red_delicious would show if the term “fruit” is shown.

  $vocabulary = taxonomy_vocabulary_machine_name_load('topic');
  $terms = taxonomy_get_tree($vocabulary->vid, 0, 1);
  $topic_options = array();
  foreach($terms as $term) {
    $topic_options($term->tid) = $term->name;
  }