List nodes of children using taxonomy_select_nodes 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' =&gt; 'DESC', 't.created' =&gt; 'DESC'),$promote) {
  if (!variable_get('taxonomy_maintain_index_table', TRUE)) {
    return array();
  }
  $query = db_select('taxonomy_index', 't');
  $query-&gt;addTag('node_access');
  $query-&gt;condition('tid', $tid);
  if ($pager) {
    $count_query = clone $query;
    $count_query-&gt;addExpression('COUNT(t.nid)');

    $query = $query-&gt;extend('PagerDefault');
    if ($limit !== FALSE) {
      $query = $query-&gt;limit($limit);
    }
    $query-&gt;setCountQuery($count_query);
  }
  else {
    if ($limit !== FALSE) {
      $query-&gt;range(0, $limit);
    }
  }
  $query-&gt;addField('t', 'nid');
  $query-&gt;addField('t', 'tid');

      // This block of code is the custom code I added.
      //SELECT only promoted article
      if($promote==1){
        $query-&gt;join('node', 'no', 'no.nid = t.nid');
        $query-&gt;condition('promote', 1);
      }
      $taxonomies=array();
      $taxonomies = taxonomy_get_children($tid);
      $taxonomies[]=$tid;
      $query-&gt;condition('t.tid', $taxonomies,'IN'); 

  foreach ($order as $field =&gt; $direction) {
    $query-&gt;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-&gt;addField($table_alias, $name);
  }
  return $query-&gt;execute()-&gt;fetchCol();
}
I would say these are your problems:

taxonomy_get_children() returns term objects, not term IDs, so that is going to break that query. This I would say is your main issue. Instead you could do this:

  $taxonomies = array();
  $taxonomies = taxonomy_get_children($tid);
  // Get the child term tids.
  $taxonomies = array_keys($taxonomies);
  // Add the parent tid.
  $taxonomies[] = $tid;
  $query-&gt;condition('t.tid', $taxonomies,'IN');


Your IN statement with the children won't work currently because earlier in the function is this line:

$query-&gt;condition('tid', $tid);


So that will only ever return values for $tid, never for the children unless you remove that line also.

Also I would recommend giving the new $promote parameter a default value, like this:

function taxonomy_select_nodes_ext($tid, $pager = TRUE, $limit = FALSE, $order = array('t.sticky' =&gt; 'DESC', 't.created' =&gt; 'DESC'), $promote = 0) {