View block with contextual filter on taxonomy term name in URL doesn't work

by C.A. Vuyk   Last Updated October 09, 2019 10:07 AM

Say, I have taxonomy vocabulary 'fruit' with terms like 'apple', 'pear' and 'grape'. Through content type 'Healthy', 'Healthy' content is made using a entity reference field to choose a term from the 'fruit' vocabulary.

Now, on a page with path /food/good/apple, a view block is placed that should show content related to taxonomy term 'apple'. I've tried to make a contextual filter like this: When the filter value is NOT available > Provide default value > 'raw value from URL' And for 'Path Component' checked 3 (for the third position in the url, 'apple') This however doesn't return any content When I remove the contextual filter, the block shows all Fruit.

To debug, I turned on 'show the query' setting on the views, below is the output. What I found remarkable, is that although I selected the third position in the url, 'apple', the query uses 'food'. But, my understanding of the query is not enough to do proper debugging.

SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid
{node_field_data} node_field_data
LEFT JOIN {node__field_fruit} node__field_fruit ON node_field_data.nid = node__field_fruit.entity_id AND node__field_fruit.deleted = '0'
WHERE ((node__field_fruit.field_fruit_target_id = 'food')) AND ((node_field_data.status = '1') AND (node_field_data.type IN ('healthy')))
ORDER BY node_field_data_created DESC   

I'm wondering if there's some kind of bug, or in what way I failed to get the desired result. I thought this could be accomplished just using Drupal core and without using contrib modules. Any help on how to get the right setup would be welcome!

Tags : views

Related Questions

Alter the moderation state in the Content view Drupal 8

Updated February 28, 2018 21:07 PM

Group items in Views by value in Field Collection

Updated July 20, 2015 13:03 PM

List of referenced entities appended to a node

Updated January 12, 2017 08:03 AM