valentine94
11/26/2014 - 9:35 AM

Getting term depth.

Getting term depth.

/**
 * Getting term depth.
 *
 * @return int
 *   Depth value.
 */
function term_depth($tid) {
  $query = "SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid";
  $parent = db_query($query, array(':tid' => $tid))->fetchField();
  return ($parent == 0) ? 1 : 1 + term_depth($parent);
}