This questions has some similarities with How to display list of nodes that share the same Parent taxonomy term as current node, but I've not managed to figure out how I can get to what I need to do given the answers there.

A have a set of nodes that are associated via term reference with a taxonomy, that is two levels deep. I'll call the parent level area and the child level task.

This is a migration from another website that has pages for publications associated with each area but in my current data structure I only associate the publication nodes with the tasks (children of the areas). The areas each have a legacy_area_id field populated with the area id that was used in the url on the old site.

What I want to do now is create a view that will listen on pub/by/area/% and take a legacy area id as a contextual filter, and show a list of all nodes associated with a child of the taxonomy term that has that value in its legacy id field.

An example:The model

With a data setup like this, a request to /pub/by/area/1

Should return a listing containing Nodes 1, 3, and 4

One option would be to go back and change my migration to associate the publications with areas too, but that seems likely to make the task of moving tasks between areas later quite a bit more complicated.

Another option would be to add the legacy area id to the tasks as well, but that provides similar challenges.

In reality, my end goal is to redirect these pub/by/area/# requests to a different view with the area name in the url similarly to what I've done for other old addresses in How to redirect based on matching a node field?. So really I suppose all the view really needs to give me is the data required to redirect to another view. I'll keep working on this, but help would be appreciated.

  • a request to /pub/by/area/1 Should return a listing containing Nodes 1, 3, and 4 What do nodes 1, 3 and 4 have in common? Same legacy id?
    – No Sssweat
    Commented Apr 13, 2016 at 6:23
  • Nodes 1,3 and 4 all are associates with tasks that are children of Area 1 which has legacy id 1
    – UltraBob
    Commented Apr 13, 2016 at 6:24
  • I only associate the publication nodes with the tasks so in your nodes you have a taxonomy reference field and in there you put task and not area, correct?
    – No Sssweat
    Commented Apr 13, 2016 at 6:30
  • That's right. In reality they are all in the Area taxonomy, so what I'm doing is only selecting child terms
    – UltraBob
    Commented Apr 13, 2016 at 7:41

3 Answers 3


visabhishek answer gave me an idea.

Create a tax term page view:

enter image description here

  • Add Legacy ID as your contextual filter
  • In FIELDS add term ID (so you will get the term ID of Area 1. You can hide it using exclude from display.)

Then using the Views Field View module

This module allows you to embed a view as a field in a view.

  • Add the view from visabhishek answer as a field. For Contextual filter you can pass the term ID as a token (using replacement patterns)

Problem solved :)

  • I'm not seeing how I can get the term id of area 1 from a term relationship that will give me some sub term of area 1?
    – UltraBob
    Commented Apr 13, 2016 at 7:45
  • @UltraBob sorry, that's what happens when I go off memory and don't test things. Updated the answer.
    – No Sssweat
    Commented Apr 13, 2016 at 8:04

My solution in two parts

I got it, and I couldn't have gotten to it without the other answers, but in the end it turns out that this solution wasn't necessary. The end goal was to redirect to a named area page and nothing about the view below gets me easy access to the tid for the appropriate area and redirect to the right page. I put in my custom module code below this. Really all the view needs to be is something that takes the legacy area id as an argument from the url

The View

I created a page and added two relationships to it:

  • Content: Taxonomy terms on node (Identifier term)
  • (term) Taxonomy term: Parent term (Identifier Area)

and a contextual filter:

  • (Area) Taxonomy term: Legacy Area ID

I still have some testing to do to make sure it is grabbing the right things, but so far it seems to be working correctly.

Getting the tid and redirecting

 * Implements hook_views_pre_render().
function env_views_views_pre_render(&$view)
    if ($view->name == 'pub_by_docid') {
        if ($view->current_display == 'pub_by_area') {
            $areaid = (int) $view->args[0];
            $query = new EntityFieldQuery();
            $query->entityCondition('entity_type', 'taxonomy_term')
                ->entityCondition('bundle', array('area'))
                ->fieldCondition('field_tax_legacy_area_id', 'value', $areaid, '=');
            $result = $query->execute();
            $tid = array_shift($result['taxonomy_term'])->tid;
            drupal_goto(drupal_get_path_alias('taxonomy/term/' . $tid), NULL, 301);


    // any other pre_render()ing here


If you can think of how I could do this better, I'd love to hear about it!

  • Interesting, looks like you found another way to do it without using Views Field View, awesome!
    – No Sssweat
    Commented Apr 13, 2016 at 8:08

Just try once following points

  • Go to admin/structure/views, find the view named Taxonomy term, and enable it
  • Go to admin/structure/views/view/taxonomy_term/edit or Clone this view and create new view with different path
  • Click Advanced (on the right)
  • Click Content: Has taxonomy term ID (with depth)
  • Select a Depth of 1 or more (how much depth term nodes you want)
  • Save all your changes

Hope it will help you...


  • Sorry, but this does not help. He wants to use the Legacy ID and not term ID as contextual filter.
    – No Sssweat
    Commented Apr 13, 2016 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.