You are here

function taxonomy_edge_get_top_tid in Taxonomy Edge 7.2

Same name and namespace in other branches
  1. 8 taxonomy_edge.module \taxonomy_edge_get_top_tid()
  2. 6 taxonomy_edge.module \taxonomy_edge_get_top_tid()
  3. 7 taxonomy_edge.module \taxonomy_edge_get_top_tid()

Get top term id.

Parameters

$tid: Term ID to get top term ID from.

Return value

integer Top term ID.

File

./taxonomy_edge.module, line 854
Selecting all children of a given taxonomy term can be a pain. This module makes it easier to do this, by maintaining a complete list of edges for each term using the adjecency matrix graph theory.

Code

function taxonomy_edge_get_top_tid($tid) {
  return db_query("\n    SELECT h.tid\n    FROM {taxonomy_term_edge} e\n    INNER JOIN {taxonomy_term_edge_path} p ON p.pid = e.pid\n    INNER JOIN {taxonomy_term_edge} pe ON pe.pid = e.pid AND pe.distance = e.distance - 1\n    INNER JOIN {taxonomy_term_edge_path} pp ON pp.pid = pe.parent\n    INNER JOIN {taxonomy_term_hierarchy} h ON h.tid = pp.tid\n    WHERE p.tid = :tid\n    AND h.parent = 0\n  ", array(
    ':tid' => $tid,
  ))
    ->fetchField();
}