I want to show several products filtered by apples. Apple is a hierarchy taxonomy and not always the values from the parents are in the childs.

Example: apple (apple can have other results that are not in big_apple nor small_aplle) -big_apple -small_apple

Question: How can I create a view that when it's 'fruit/apple' shows apple + big_apple + small_apple and whent it's 'fruit/big_apple' it will only be 'big_apple' ?

I think with this in contextual filters can help but it's far from working:

$id= taxonomy_get_term_by_name($argument);
$children = array_keys(taxonomy_get_children($id));
    $handler->argument .= '+' . implode('+', $children);
    return TRUE;
    return FALSE; 

1 Answer 1


Well, I am my most popular fan so I will answer myself:

1. It's not possible to add that PHP code to the view, as it's a known bug that the view doesn't allow multiple contextual filter variables as a PHP. Although you can use them through the URL and changing the 'code PHP' option by 'Multiple Terms ID separated by ',' OR '+''. --> I don't like that option as the URL won't be very clean and can be a bit complicated.

2. Found a better option!! I decided to select the parent when one of its childs are selected. This option can be activated as automatically, when installing the Taxonomy Term Reference Tree Widget module:

About this module

This module provides an expandable tree widget for the Taxonomy Term Reference field in Drupal 7. This widget is intended to serve as a replacement for Drupal's core Taxonomy Term Reference widget, which is a flat list of radio buttons or checkboxes and not necessarily fit for medium to large taxonomy trees.

Note: I don't know why but my tree view is not as nice as in the picture and I needed to use a fix but it works perfect.

Your Answer

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

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