Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_views_query_alter().
- */
- function internetdevels_views_query_alter(&$view, &$query) {
- if ($view->name == 'view_faq' && $view->current_display == 'page') {
- $arg = arg();
- $tid_key = '';
- foreach ($query->where[1]['conditions'] as $key => $value) {
- if ($value['field'] == 'taxonomy_term_data.tid') {
- $tid_key = $key;
- }
- }
- if (!isset($arg[1])) {
- $condition = 0;
- }
- if (isset($arg[1]) && is_numeric($arg[1])) {
- $condition = $arg[1];
- }
- $parents = db_select('taxonomy_term_data', 'td');
- $parents->join('taxonomy_term_hierarchy', 'th', 'td.tid = th.tid');
- $parents
- ->condition('th.parent', $condition)
- ->condition('td.vid', 1);
- $parents->fields('td', array('tid'));
- $results = $parents->execute();
- $tids = array();
- while ($value = $results->fetchAssoc()) {
- $tids[] = $value['tid'];
- }
- $query->where[1]['conditions'][$tid_key]['field'] = 'taxonomy_term_data.tid';
- $query->where[1]['conditions'][$tid_key]['value'] = array();
- $query->where[1]['conditions'][$tid_key]['operator'] = 'IN';
- $query->where[1]['type'] = 'AND';
- $query->where[1]['conditions'][$tid_key]['value'] = $tids;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement