Score:0

Filter views by field value equals another field of curent node

gu flag

D9.3. All fields are not referenced, they are just simple integers. All data was pulled from a huge external API and it was not possible to create all references.

Just for ease of understanding, imagine a book database website with books and characters. But each character is presented in one book only.

So, book node has field_book_id, which is numeric, unique, but not NID. Also it has a multiple field_character_ids with a list of ids of all characters in this book.

A character node has its own field_character_id (matching with field_character_ids from book node). And also field_my_book_id, which equals to book id field.

The goal is to create a View, which will show the current book's characters in a list.

I'm using Views Contextual Filter Default Entity Field Values module which allows to pull fields values from the current node, for example.

But in Views Filter Criteria I can't match the selected field with the value from the Contextual Filter. It has only pre-defined operators, such as is equal to, is less than, is greater than, etc. And I can't select something like "Match value from contextual filter". I tried to use twig and replacement patterns there without any luck.

It would be a very simple database query, but is it possible to get it working in Views?

Score:0
gu flag

Ok, it was rather simple.

In contextual filter add the field you want to target.

Then: When the filter value is NOT available > Provide default value > Field value from current entity > under Entity Field select field which will filter the view results.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.