I'm using Drupal 8.

I have a book content type that uses a vocabulary called "book type" as an entity reference field.

I have basic page content type which also uses the the vocabulary "book type" as an entity reference field.

So both of the content types are using the same vocabulary.

What I'm trying to do is filter the books by the chosen book type on the basic page content type, but I just can't figure it out. Here's what I tried.

drupal view

drupal view drupal view drupal view drupal view

This is the book content type, which uses the vocabulary "book type" in an entity reference field drupal view drupal view

This is the basic page content type which also use the vocabulary "book type" in an entity reference field drupal view drupal view drupal view

This is my second try with the help of prkos: drupal view

  • That type is the field that is used on both CTs? It's not an Entity Reference field? Maybe a text list? BTW narrow your screen next time when taking screenshots so you don't have so much empty spaces making them harder to read. – prkos May 16 at 19:58
  • @prkos Thanks for checking it out! Yes the field is in used on both CTs and It's an entity reference field. Sorry about the images, I just uploaded better ones. – Charly May 16 at 20:49

You don't need Relationships for matching through ER fields, IDs are enough so it's enough to use the ER field Contextual matching directly.

Instead of the ID Contextual filter add the Contextual filter for the ER field and configure it:
When the filter value is NOT available
Provide default value
Taxonomy term ID from URL
Load default filter from node page, that's good for related taxonomy blocks
Limit terms by vocabulary
[Your vocabulary]
Filter to items that share any term
When the filter value IS available or a default is provided
Specify validation criteria
Taxonomy term ID
[Your vocabulary]

Set other options according to your needs.

You can test it by entering a Taxonomy ID into the Views Preview field, you should get only the nodes that reference that term.

When you place the Block in a theme region also configure the Contextual option, it won't work without it.

  • Thank you for your help! When i type in a Taxonomy ID I just get "related book block" as the result, which is the name of the block. – Charly May 16 at 23:13
  • Did you configure the No results text? Maybe you're entering an ID that isn't referenced from any content? What happens when you enter all into Preview? Add to the question info with the configuration for the Contextual. – prkos May 16 at 23:40
  • I just configured the no results text, so now when I enter a known taxonomy id i just get "no results found", and i'm 100% sure the taxonomy term is correct. The taxonomy term id of "resources" is 11, so i just typed in 11 on views preview field. – Charly May 17 at 0:27
  • Is your last screnshot correct? It says your Contextual is Content ID, and not the ER field. – prkos May 17 at 0:46
  • Yes the i uploaded the correct screenshot, but wow it seems like i didn't follow your instructions correctly. I cannot fiend an Entity reference field on the list of contextual filters. Is it called something else? Is the one called "Has taxonomy term ID"? – Charly May 17 at 1:06

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.