0

I have two content types:

  • Programs
  • Events

I have a vocabulary:

  • Programs

I have a view that displays Events, and I place the view in my Programs nodes.

Both Programs and Events have a field_term_programs that references the Programs vocabulary. If I place the view in a Programs node, I want it to display any Events assigned to the same Programs term as that Programs node. I have tried to set this up using contextual filters but have had no luck thus far. The views block is displayed in the Programs node, but no nodes are displayed within the block.

1 Answer 1

1

The request to show sibling nodes through Taxonomy is one of the most common Views requests.

You case seems to be the simplest one, you can use the Has taxonomy term ID Contextual filter.

  1. Create your Views listing Events
  2. Add the Has taxonomy term ID Contextual filter 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
    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]
    Single ID

  3. Place your Block Display on Programs nodes and configure Block settings for the contextual filter.
6
  • It's not working yet. I don't know why we would choose "Taxonomy term ID from URL" when there is no taxonomy term ID in the URL, but I did so anyway. Also, I'm not sure what "configure block settings for the contextual filter" means. Thanks for your response.
    – arnoldbird
    Jul 3, 2019 at 19:59
  • The wording can be a bit confusing, Views is a very complex and featurefull module. That option isn't referring to getting the info from the actual URL text, but from the node context. The following option illustrates that, you've chosen to pull information into your Views about the node that is currently being viewed, the info about the Taxonomy terms. After creating a Block display in your Views, you have to place the Block in a region in your theme so it can be displayed somewhere on your site. In those settings you'll see where you have to select again sth like "taxonomy term from url".
    – prkos
    Jul 3, 2019 at 21:19
  • "you have to place the Block in a region in your theme so it can be displayed somewhere on your site". The block is already displayed. There are just no nodes being displayed within the block. I see the block title. And if I select "Display contents of 'No results found'" instead of "Provide default value," I can see the "No results" message. I edited my question to clarify that the block is being displayed.
    – arnoldbird
    Jul 8, 2019 at 12:55
  • Please add a screenshot of your Contextual filter configuration, and your Block configuration to your Question.
    – prkos
    Jul 8, 2019 at 13:16
  • It's working now. Your instructions are correct, but didn't work initially. It seemed to start working when I removed the contextual filter altogether, and then removed a filter criteria, forcing some nodes to display. I then added the filter criteria back, then added the contextual filter, and then it worked. It's as if some cache had to be cleared that would not clear unless some filters were removed and then re-created.
    – arnoldbird
    Jul 8, 2019 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.