You are here

function _term_merge_select_nodes in Term Merge 5

Same name and namespace in other branches
  1. 6 term_merge.module \_term_merge_select_nodes()

Returns the results of a query for nodes associated for the specified $tid. (Thanks, Aldo!)

1 call to _term_merge_select_nodes()
term_merge_merge_form_submit in ./term_merge.module
Actually merges the terms

File

./term_merge.module, line 147

Code

function _term_merge_select_nodes($tid) {

  // I would have liked to use taxonomy_select_nodes() instead, but that function
  // either uses a pager, or returns only the latest n nodes, and we need all of them
  // (including unpublished nodes)
  // generate an array of descendant term IDs to the right depth.
  $descendant_tids = array();
  $term = taxonomy_get_term($tid);
  $tree = taxonomy_get_tree($term->vid, $tid, -1, NULL);
  $descendant_tids[] = array_merge(array(
    $tid,
  ), array_map('_taxonomy_get_tid_from_term', $tree));
  $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
  $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (' . $str_tids . ')';
  $result = db_query(db_rewrite_sql($sql));
  return $result;
}