Other (related) nodes with the same taxonomy block grouping problem Quick view: I want to create a views block that lists all other nodes that have the same taxonomy term(s) and I want to group the related nodes by term.



I have trouble while doing this:

The content type has some taxonomy terms fields and one of them is my_taxonomy_field. I can enter multiple values to this field.

What I basically want is to show all other nodes tagged with the term(s) on this node and group them by terms. I could do this by contextual filters (content: has taxonomy term ID + ) as explained here or here.



Let me explain:



This is my node list:


NODE 1 taxonomy term field: term 1, term 2, term 3
NODE 2 taxonomy term field: term 3, term 4
NODE 3 taxonomy term field: term 5, term 6, term 7
NODE 4 taxonomy term field: term 6, term 7
NODE 5 taxonomy term field: term 1, term 3
NODE 6 taxonomy term field: term 1
NODE 7 taxonomy term field: term 8
NODE 8 taxonomy term field: term 2, term 9




Let's look at NODE 1, it has these terms: term 1, term 2, term 3

And the terms are tagged on that nodes:

term 1: node 1, node 5, node 6

term 2: node 1, node 8

term 3: node 1, node 2, node 5



This is the related nodes block based on the taxonomy term field:


node 1 (excluded)
node 2 
node 5 
node 6 
node 8




I want to group them by terms as that (note that current node (node 1) excluded):

BLOCK


TERM 1


node 5
node 6

TERM 2


node 8

TERM 3


node 2
node 5





I tried to this with that way: views -> style -> settings (grouping field) and I selected the taxonomy term field. It does what I want, not what I want actually, more than what I want because it creates a views block as that:

BLOCK


TERM 1


node 5
node 6

TERM 2


node 8

TERM 3


node 2
node 5

TERM 4


node 2

TERM 9


node 8





This views doesn't add any (irrelevant) nodes to the list, the nodes are the same with the un-grouped one but because node 2 and node 8 are tagged with other terms, other terms listed here.



How I could list related nodes as grouped but without this 'unwanted' terms, with only the terms in the current node?

(Note: I'm working on both two ways mentioned above, these are the screenshots of them):



Method 1:




Method 2
I've used tags as the term field, so adjust for that.

Create the block view as follows:

A view of content (nodes).

Relationships:


Content: Tags (field_tags), require relationship  // you will use your term field here
Taxonomy term: Content using Tags (Relate each Content with a Tags set to the term.) and set the relationship to the first relationship added, and tick require this relationship // yours will be named differently


Contextual filters:


Content: Nid (node id). Set the relationship to the second relationship added. Provide a default value of Content ID from URL for WHEN THE FILTER VALUE IS NOT AVAILABLE. Specify a validation criteria of Content -> your content type -> Node ID -> Hide view
Content: Nid (node ID). DO NOT USE A RELATIONSHIP. Provide a default value of Content ID from URL for WHEN THE FILTER VALUE IS NOT AVAILABLE. Specify a validation criteria of Content -> your content type -> Node ID -> Hide view. Click on more and tick Exclude.


Fields:


Content Title (NO relationship)
Taxonomy term: Name, use relationship 1, and hide from display


Sort Criteria


Taxonomy term: Name, use relationship 1, ascending
Content Title, ascending


Filter Criteria

Add a filter of Content (node) type to filter on your content type.

Format:

Unformatted list, with settings: Grouping field Nr.1 set to the term field (field 2)