I want to list nodes from children terms using or editing taxonomy_select_nodes function. Actually I added these few lines but I get an infinite loop or slow response:
function taxonomy_select_nodes_ext($tid, $pager = TRUE, $limit = FALSE, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC'),$promote) {   if (!variable_get('taxonomy_maintain_index_table', TRUE)) {     return array();   }   $query = db_select('taxonomy_index', 't');   $query->addTag('node_access');   $query->condition('tid', $tid);   if ($pager) {     $count_query = clone $query;     $count_query->addExpression('COUNT(t.nid)');      $query = $query->extend('PagerDefault');     if ($limit !== FALSE) {       $query = $query->limit($limit);     }     $query->setCountQuery($count_query);   }   else {     if ($limit !== FALSE) {       $query->range(0, $limit);     }   }   $query->addField('t', 'nid');   $query->addField('t', 'tid');        // This block of code is the custom code I added.       //SELECT only promoted article       if($promote==1){         $query->join('node', 'no', 'no.nid = t.nid');         $query->condition('promote', 1);       }       $taxonomies=array();       $taxonomies = taxonomy_get_children($tid);       $taxonomies[]=$tid;       $query->condition('t.tid', $taxonomies,'IN');     foreach ($order as $field => $direction) {     $query->orderBy($field, $direction);     // ORDER BY fields need to be loaded too, assume they are in the form     // table_alias.name     list($table_alias, $name) = explode('.', $field);     $query->addField($table_alias, $name);   }   return $query->execute()->fetchCol(); }