site building

taxonomy_with_parents_12

 

Step 1: Create a vocabulary
To nest terms and group them together with their parents, drag the child term (ingredients) in the hierarchical order below their parents. Drupal will now notice that the child terms belong to its parent terms.

taxonomy_with_parents_1

 

Step 2 (optional): Create a paragraph to organize a parent and its child term

This step is technically not required, but it results in a smoother user experience. Use an entity reference field that references the vocabulary (in this case Food) twice, to have a reference for the parent and the child term.

taxonomy_with_parents_3

 

Step 3: Place the vocabulary (if you used a paragraph, place it here) on the content type

If you didn't use a paragraph type for your scenario, place two entity reference fields with your used vocabulary, like described in Step 2.

taxonomy_with_parents_3

 

Step 4: Choose a reference method

The next step will be the most important step in this tutorial. We need to find a way to display the parent as well as the child in term separated from each other.  To enter the settings, go to your paragraph type, click on edit on the related field and take a look at the reference type settings (if you are not using a paragraph, navigate to the entity reference field on your content type). With using the default reference method, there will be available ALL terms within the vocabulary. So we need to filter each entity reference field for parent and child. We can achieve this with using an entity reference view.

taxonomy_with_parents_4

 

Step 5: Creating an entity reference view

Our goal is to create two separate entity reference views, one for the parent term and one for the child term.
Choose Content from your content type as base of the view.

taxonomy_with_parents_5

 

taxonomy_with_parents_6

 

 

Create a new view display as entity reference twice, one for the parent and one for the child terms.

 

Use as field Taxonomy term: Parent name for the parent terms.Use as field Taxonomy term: Name for the child terms.

 

taxonomy_with_parents_7

 

 

 

taxonomy_with_parents_14

 

Filter for: Taxonomy term: Vocabulary and your vocabulary and use as filter selector is NOT equal to.
This causes to exclude the child terms.
Filter for: Taxonomy term: Vocabulary and your vocabulary and use as filter selector is equal to.
This causes to exclude the child terms.
taxonomy_with_parents_9

 

taxonomy_with_parents_8

 

Step 6: Use the entity reference view as referenced method on your fields settings

Navigate to your content type, then to Manage fields and edit the entity reference field for your term.
Set as reference method Views: Filter by an entity reference view and choose your view depending on the entity reference field.

taxonomy_with_parents_11

Reproduce this for your second entity reference field.

Step 7: Lean back and watch the result

taxonomy_with_parents_12