Taxonomy in Contextual filters for Views
Solutions
I cloned the existing default view for taxonomy/term/%, removed all the contextual filter already existing, and then:
- I added a new relationship, "Content: Taxonomy terms on node."
- I added a new context filter, "Taxonomy vocabulary: Machine name," for which I didn't change any setting. (The Views module already selected the relationship I defined before.)
- I added a new context filter, "Taxonomy term: Term ID."
For the "Taxonomy term: Term ID" filter I used the following settings.
I changed the path for the view to "test-term/%" and removed the feed.
The setting page for the view, once done the changes I described, appears as in the following screenshot; I highlighted the parts that are different from the setting page for the view I cloned.
What I obtained is a view that shows the nodes containing the terms from the vocabulary for which I pass the machine name as first argument.
For http://tero.local/dr71/test-term/tags ("tags" is the machine name for a vocabulary I defined in my test site), I get the following result.
For http://tero.local/dr71/test-term/tags/tags (the second "tags" string is the name of a taxonomy term that the "tags" vocabulary has), I get the following.
I didn't find any way to filter out the duplicates that appear in the first case, though. This is would happen only for those vocabulary that allows the users to select more than one term per node.
The relationship with the taxonomy terms is necessary as the view is about nodes; without the relationship, it would not be possible to use "Taxonomy vocabulary: Machine name," and "Taxonomy term: Term ID" as contextual filters. You can check it: If you remove that relationship, you will not able to add them as contextual filters.