The easiest way to achieve this is by using Views.
The links rendered in Taxonomy fields (Entity reference fields) are set to go to Taxonomy term pages. The links are constructed with Taxonomy term ID in the URL: taxonomy/term/[TID]
.
Taxonomy term pages are created using Views, so you can easily Edit the relevant Views to adjust it to your needs. The modification you're after is adding a Contextual filter that filters out only one content type.
With that modification you could type, for example, taxonomy/term/10/article
in the browser address bar, and the usual Term page for term 10 would list only results of the Article Content Type.
The other part of your question is how to make the Taxonomy reference link on the node View be sensitive to the Content type it's on, so when it's clicked it goes to the filtered list, and not the general term page that shows all results.
The easiest way to do that is to hide that field from displaying and replace it with a Views Block that would output a similar link, only Contextually sensitive to the term, and to the Content type.
Here are the steps on how to achieve this:
Make term pages sensitive to Content types
- Duplicate the
Taxonomy term
View (it's better to keep the default ones as they are, so you don't mess up the original features and it makes updates more straightforward). Rename it to make sense (Taxonomy term-Content type)
- Add a new Contextual Filter Content type from the
Content
Category (keep the one sensitive to the taxonomy term that is already there, we need it) and configure it with these options:
When the filter value is NOT in the URL
Display all results for the specified field
When the filter value IS in the URL or a default is provided
Override title
Content tagged with {{ arguments.tid }} of type {{ arguments.type }}
Specify validation criteria
Validator
Content type
Validate user has access to the Content type
More
Transform spaces to dashes in URL
- Edit the
Path
to add another %
to react to the Contextual filter we just added, so you end up with the Path: taxonomy/term/%/%
- Go to the other Display in the same View called
Feed
and edit the Path there to read taxonomy/term/%/%/feed
- Save the View. You can test it by entering the relevant arguments into Preview inside Views (for example
10/article
) or by typing the URL into your browser addressbar (example.com/taxonomy/term/10/article
).
- Optional but good UX: add No results behavior Text area
No content of type {{ arguments.type }} tagged with {{ arguments.tid }} has been found.
on your Page display and override for that Display only This page (override).
Create taxonomy links on Nodes sensitive to CT
To create links sensitive to the context we need Views Display Block of type Content. We can add it to the Views we created above (because that View is of type Content), or create a completely new View for this. Since this Block Views will be sufficiently different it's better to create a new View for this. Here are the steps for adding a new Views to accomplish this:
- Create a new Views of type Content showing Fields, add a Block Display to the View, change its name to something meaningful you can recognize later on Blocks page:
Taxonomy term link sensitive to CT
- Add a Filter to limit to your desired Content types (event, course, video)
- Under
Format
option Show
settings choose to Hide empty fields
- Add a new Field City (or whatever your field is called), Exclude from display, and don't tick
Link label to the referenced entity
- Add a new Field
Content type
, Exclude from display and set Formatter
to Entity ID (so you get CT machine name so the contextual filter later works correctly)
- Add a new Relationship Taxonomy term referenced from field_city and Require this relationship
- Add a new Field Term ID (it will use the Relationship from previous step), Exclude from display and set
Formatter
to Unformatted
- Add a new Field Custom text from
Global
Category and configure it:
Create a label just tomake it easier to build, enter Taxonomy link sensitive to CT
In Text area enter {{ field_city }} (type { type }})
Rewrite results
Output this field as a custom link
Link path: taxonomy/term/{{ tid }}/{{ type }}
Replace spaces with dashes
No results behavior
Hide if empty
Add a new Contextual filter ID from Content
Category and configure:
When the filter value is NOT available
Provide default value
Content ID from URL
When the filter value IS available or a default is provided
Specify validation criteria
Content
[your CTs video course event]
Now when you enter a node ID into Preview it will show the link to taxonomy term page that has content type argument added to it at the end.
- Set
Pager
to Display a specified number of items to 1
item
- Remove the Title field so you end up with only the Custom text visible and Save the View
- Place the Block in
Content
region, don't Display title
, set Content ID
to Node from URL, limit which Content type to show the Block on
- Edit your Content types (all three)
Manage Display
to hide the City Taxonomy Field (drag to Disabled)
And now you have the relavant Taxonomy term link that has the added Content type at the end to call on Views term page that will filter out only that content type.