0

I have created a view and added indexed fields to that view to show content.

I want to show content related to taxonomy "related place" as well as its related child taxonomy content. For selecting child taxonomy I used simple hierarchical module, but the problem I am facing is that I'm not getting any option to select Indexed:has taxonomy term id(with depth) in contexual filter to show content .

The propose of using indexed fields in views for filtering content using facet api.

I've tried everything to achieve this, but no result.

0

In custom module

  • you can use hook__views_pre_view to change contextual filter,
  • add children terms till depth to the contextual filter,
  • function taxonomy_get_children_all() defined below, will fetch all child terms till depth:
  • In view, don't forget to allow multiple value contextual filter for contextual filter.

    function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
      $c = taxonomy_get_children($tid, $vid, $key);
      $result = array();
      foreach ($c as $t => $d){
        $result[$t] = $d;
        $below = taxonomy_get_children_all($t, $vid, $key);
        if (!empty($below)) {
           foreach ($below as $nt => $nd){
             $result[$nt] = $nd;
           }
        }
     }
     return $result;
     }
    
    
     function formalter_views_pre_view(&$view, &$display_id, &$args){
     if($view->name == "category_view") { // && $display_id == "page") {
       $vid = <Your vocabulary id>;
    
       $t = $args[0];
    
       $tt = taxonomy_get_children_all($t,$vid);
       foreach($tt as $k => $v) {
         $a = (string)$k;
         $args[0] = $args[0] . "+" . $a;
       }
     }
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy