Show top level terms in a term type view

I recently needed to create a view of type "Term" that displayed taxonomy terms and their description for a certain vocabulary.

The setup for that was quite simple

  • Create a view of type "Term"
  • Add an argument of Vocabulary ID
  • Add a field of  "Term Name" and another of "Term Description"
  • Add a filter of "Vocabulary" and select the vocabularies you want to restrict to

This gives a nice simple view of all terms belonging to a single vocabulary when the vocabulary id is passed as an argument.

The problem I had here is that this view shows all terms, and I just wanted to see the top level terms in a hierarchical vocabulary.

I instantly went looking for a depth modifier filter or argument handler, but no such luck, you just can't restrict to a level in the hierarchy.

Then I remembered relationships and thought that I might be able to use that based on the simple assumption:

If a term has no parent then it must be a top level term

Armed with this knowledge it was then really simple to get the view restricted to all top level terms.

  • Add a relationship of Taxonomy: Parent term
  • Add a new filter of Taxonomy: Term ID and set it's relationship field to the relationship above, and set it's Operator to Is Empty.