Search code examples
drupaldrupal-viewsdrupal-themingdrupal-8drupal-contextual-filters

View: Exclude nodes that have the same taxonomy term id(s) as current node


Drupal 8

I have a content type with a field that holds a Taxonomy Term Reference. I want a View that shows other nodes of the same content type that do not have that field with the same Taxonomy Term ID as the currently viewed node.

Example:

URL: /story/storyA

Currently viewing a node of Content Type Story that has a Taxonomy Term Reference to value B. I need the view to show other stories that do not have that same Taxonomy Term Reference to value B.

I thought I could achieve that by

  • Set up a relationship to the field that holds the Taxonomy Term
  • Add a Filter Criteria of Term ID associated to above relationship and with operator is not equal to. PROBLEM: how do I get the token for Value?

enter image description here

I also tried to go about adding a Contextual Filter associated to the created relationship and selecting Exlude but no dice.

enter image description here


Solution

  • I finally figured it out, I was missing the adequate additional Contextual Filter:

    • Term ID , Provide default value with Taxonomy term ID from URL and the options Load default filter from node page and limit terms by vocab checked. And the last bit, in More, I have Exclude checked. This contextual filter is associated to the created relationship mentioned in the question.