2

I am creating a view which takes a tid as an argument. I then want to generate the full list of tids which includes the one directly referenced plus all those above it in its taxonomy.

How could I do this?

2

I guess you can't do it directly in views. You can use "Contextual filter: Taxonomy term: Term ID" and write small php code by selecting "Provide default value".

enter image description here

Here is the code you can use:

$parent_terms_string = '';
$current_tid = 3; //The term ID of whose all parents you want to fetch.
$parent_terms_tid_array = array();
$parent_terms_array = taxonomy_get_parents_all($current_tid);
foreach($parent_terms_array as $term){
  if($current_tid != $term->tid){
    $parent_terms_tid_array[] = $term->tid;
  }
}
$parent_terms_string = implode('+',  $parent_terms_tid_array);
return $parent_terms_string;

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.