Drupal 8 - Show only parent term using views

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 taxonomy view
  • Choose the vocabulary in filter
  • Add the description field

This gave me the list of all the terms under the vocabulary.

But, the view has to show only the parent terms or the top level terms in the vocabulary herirarchy.

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, it struck me that a term with no parent is the top level term or parent term based on the Relationships.

With this assumption, it was fairly simple to get the parent terms

  • I added a relationship - Relationship: Parent Relationship config
  • Under filter criteria added Taxonomy term: Term ID
  • Added the Relationship: Parent
  • Selected Is Empty (NULL) under operator Filter config

Voila. I got the parent terms under the vocabulary.

Category view