Blog

Drupal Views - Taxonomy Term ID Depth Modifier

By pferlito

November 18, 2014

When creating a Drupal view with taxonomy term filtering it is possible to vary the results of the view by using contextual filters. One little-understood contextual filter is the Taxonomy Term ID Depth Modifier. It's used in conjunction with the "taxonomy term id (with depth)" contextual filter to make the views results dynamic.

In particular the Taxonomy Term ID Depth Modifier option allows you to reuse the same view to query nodes according to varying depths in the taxonomy tree. For example let's say this is your taxonomy.

North America (term id:7)
- Canada
- Mexico
- United States
-- California
--- San Francisco
--- Los Angeles
--- etc

With a term id of 7 and a depth modifier of 0 your query would include nodes tagged with "North America". With a depth modifier of 1 your query would include nodes tagged with "North America", "Canada", "Mexico" and "United States". The term depth modifier is passed as the second argument (Contextual Filter in Drupal 7) to the view, separated by a slash. So if the term id is 7 and the depth modifier is 2 the view's url would be "view_name/7/2".