Show Only Specific Levels of Taxonomy in Views

Show Only Specific Levels of Taxonomy in Views

One OSTraining member asked us this question:

How can I set the filter criteria so that Views shows only the second level of a taxonomy?

We’ve had that question from other members before, so here’s a tutorial explaining how it’s done.

First, you need a taxonomy that has parent and child terms, as in this example:

Drupal taxonomy with parent and child terms

Let’s show you how to set up Views so that only the child terms show: Amphibians, Birds, Fish, Mammmals, Reptiles.

  • Go to Structure > Views > Add new view.
  • Create a View that shows “Taxonomy terms”.
creating a Drupal view with taxonomy terms

Thanks to Beth Binkovitz for the solution to this next step.

  • Click “Add” next to Contextual Filters.
  • Search for and choose “Taxonomy term: Parent term”.
  • Click “Apply (all displays)”.
  • Provide default value: check this box.
  • Type: Fixed value
  • Fixed value: enter the parent terms for your sub-terms
  • Specify validation criteria: check this box.
  • Validator: Taxonomy term.
  • Vocabularies: Choose your vocabulary,
  • Filter value type: Term name converted to term ID
  • Click “Apply (all displays)” to finish.
  • Save the filter and save your view.
  • You should now see that the parent terms are ignored:
A Drupal view with only child terms

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
5 Comments
Oldest
Newest
Inline Feedbacks
View all comments
dench0
dench0
8 years ago

You are wrong. Pid is not level or depth, this is id of parent term. In this example you just show terms which has parents (pid = 0 indicates that term has no parent).

You wrote:
The top level taxonomy terms have a value 0.

The second level terms have a value of 1.

The third level terms have a value of 2 etc.

This is not true. For example: if you filter by “Is greater than or equal to” and then enter a “Value” of 10″ – views does not display 10th level of taxonomy, it show terms which parent term id greater than or equal to 10.

steve
steve
8 years ago
Reply to  dench0

@dench0 Yes, you’re right. Sorry, I messed this up. I will update the tutorial.

dench0
dench0
8 years ago
Reply to  steve

You still have error in text. This is also wrong:

The top level taxonomy terms have a value 0.

The second level terms have a value of 1.

The third level terms have a value of 2 etc.

steve
steve
8 years ago
Reply to  dench0

Yes, nothing had been updated when you posted again.
Try now.

dench0
dench0
8 years ago
Reply to  steve

Yes, now article is correct. BTW if you really want to restrict showed terms by level(depth) you need to do something like this:

1. [url=http://awesomescreenshot.com/04b5kgfba5]http://awesomescreenshot.co…[/url]

2. here example of relation “Parent 3” [url=http://awesomescreenshot.com/03a5kgfr5a]http://awesomescreenshot.co…[/url] . Previous two relation have same principle

3. here filter screen [url=http://awesomescreenshot.com/0215kgfu46]http://awesomescreenshot.co…[/url]

At result you will see terms only from fourth level.

5
0
Would love your thoughts, please comment.x
()
x