1

I have a hierarchical taxonomy vocabulary of page categories:

Category A
  - Category A1
  - Category A2
Category B
  - Category B1

I would like to list some of them (conditionally) as options on my Page content type. For that, I am using an Entity Reference field, with the "Views" reference method.

Reference type

I created a Taxonomy view with the Entity Reference display for that, but this way, the categories display as options without hierarchy:

Categories displayed without hierarchy

Is there any way to selectively display taxonomy terms as field options on a content type, maintaining the hierarchy?

1

I just came across this question, because I had the same issue. The solution I've found is to use a Relationship; no extra modules required.

  1. Add a Relationship and choose "Parent Term". Check on "Require this Relationship" in the dialog box.
  2. In the "Filter Criteria" section of the view, add the "Term" field (NOT the "Parent" field*). If you want, you can choose to show the hierarchy in a dropdown, in prep for choosing the term in step 4.
  3. Choose the created Relationship in the "Relationship" field of the filter dialog box.
  4. Choose the Parent term in that same filter dialog box (to use your example, say "Category A").

Now your view should output only the children of that parent term. (Again, using your example, if you chose Category A, your view would output:

Category A1
Category A2

*there is a "Parent" field in the Filter field options, and it seems intuitive to use that, but using that only outputs the top-level hierarchy of the Taxonomy, even when combined with an AND with the Taxonomy field. Maybe a bug?

0

IMHO, the best module to show hierarchical taxonomy options on a form is Term Reference Tree.

Unfortunately, the D8 version development has stalled out a bit. But it is still useful. I recommend the dev version with the patch from this issue:

Allow to configure widget settings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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