I have a hierarchical general taxonomy vocabulary called tags. Some of the terms are only relevant to particular content types; e.g., the "Apples" content type might have a sub-tree in the vocabulary with Cox, Granny Smith, and the "Oranges" content type might have Seville in its vocabulary sub-tree.
When editing an Apple node, I don't want users to be able to select Seville as this doesn't make sense.

I have put the terms into one vocabulary because other content types (e.g. blog articles) might want to tag against any of these.

1 Answer 1


I think http://drupal.org/project/term_reference_tree together with views will handle this for you. You will need to set up different views for each content type and then use term_reference_tree together with that view on each content type. As quoted from the module:

If you want to filter by a view, make sure the view includes the taxonomy term ID, and that the items per page is set to unlimited, as the widget will only display the items from the first page of results.

Summarised module usage for reference:

  1. Create a view to filter for the terms you want.

    • Choose Taxonomy for the content, and work on the Master display (not Page or Block)
    • Add the Name field
    • Add the Taxonomy term: Term ID field BUT check the "exclude from display" option.
    • Turn off the pager
    • For this specific case, add relationship: Parent term; create OR group in filter: (vocab=tags && (parent.tid={Apples's tid} || tid={Apples's tid}). This gives the Apples term itself and all its child terms.
    • Possibly needed if view does not work for non-admin users: change the Disable SQL Rewriting option under Query settings, but beware that means there is zero access checks on your view.
  2. Apply the view to the Term Reference field.

    • Go to the content type fields page.

    • On the Term Reference field in question, click the Edit link at the end of the row. You can now see the "Filter by view" option. (If not, your view is wrong). Choose your view and save these options.

    • Now click the link to change the widget: choose Term Reference Tree.

  • Thanks for pointer. I've installed, set the widget, made a view for the tags that I want, but can't for life of me find how to "filter by a view". Is there a UI for this? Commented Jan 17, 2012 at 12:08
  • You add your new field > term reference > term ref tree. Choose your vocab. Now you should reach the main settings page where you will have a "Filter by view" option. If you dont then you dont have a taxonomy based view set up yet. To do so, go to views > add view. Remove page checkbox, change content to taxonomy terms and continue and edit. Add taxonomy term ID to the fields, change pager to display all items, then add a filter based on the taxonomy terms you want included for that content type. Save and then go back to the field settings and you should now be able to select the view.
    – 7wonders
    Commented Jan 17, 2012 at 12:25
  • Thank you. I was looking at the Widget settings not the Field settings. I've been able to select my view but now there's no tags at all(!) despite the view's Master display clearly returning the correct tids. I've tried only returning tids; I've tried returning tids and other fields; I've tried making sure the parent (Apples) tid is included. But still, zero tags listed as editable. The view doesn't have contextual filters or anything fancy like that. So near...yet so far! Commented Jan 17, 2012 at 13:23
  • For fields have Taxonomy term: Name AND Taxonomy term: Term ID BUT exclude Term ID from display. Then, in filters have a Vocab filter and filter on the same Vocab AND Taxonomy term: Name (=Apples) filter. This is working perfect on my dev box.
    – 7wonders
    Commented Jan 17, 2012 at 13:31
  • Thanks so much! Almost there. So: I do as you said, hide the tid field. Yes! big step forward. But I needed more voodo: add relationship:parent term; create OR group in filter: (vocab=tags && (parent.tid={Apples's tid} || tid={Apples's tid}). So I have Apples and all child terms. Finally it shows up as expected. But for user 1 only. Other users still see nothing. I've removed access restriction from the view (was only view published content anyway); cleared caches; still nothing. Commented Jan 17, 2012 at 14:50

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.