Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. /**
  2.  * Implements hook_views_query_alter().
  3.  */
  4. function internetdevels_views_query_alter(&$view, &$query) {
  5.   if ($view->name == 'view_faq' && $view->current_display == 'page') {
  6.     $arg = arg();
  7.     $tid_key = '';
  8.     foreach ($query->where[1]['conditions'] as $key => $value) {
  9.       if ($value['field'] == 'taxonomy_term_data.tid') {
  10.         $tid_key = $key;
  11.       }
  12.     }
  13.  
  14.     if (!isset($arg[1])) {
  15.       $condition = 0;
  16.     }
  17.     if (isset($arg[1]) && is_numeric($arg[1])) {
  18.       $condition = $arg[1];
  19.     }
  20.  
  21.     $parents = db_select('taxonomy_term_data', 'td');
  22.     $parents->join('taxonomy_term_hierarchy', 'th', 'td.tid = th.tid');
  23.     $parents
  24.       ->condition('th.parent', $condition)
  25.       ->condition('td.vid', 1);
  26.     $parents->fields('td', array('tid'));
  27.     $results = $parents->execute();
  28.     $tids = array();
  29.     while ($value = $results->fetchAssoc()) {
  30.       $tids[] = $value['tid'];
  31.     }
  32.     $query->where[1]['conditions'][$tid_key]['field'] = 'taxonomy_term_data.tid';
  33.     $query->where[1]['conditions'][$tid_key]['value'] = array();
  34.     $query->where[1]['conditions'][$tid_key]['operator'] = 'IN';
  35.     $query->where[1]['type'] = 'AND';
  36.     $query->where[1]['conditions'][$tid_key]['value'] = $tids;
  37.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement