Dan
-
04:59:21 pm on December 13, 2011 | # |
Here’s a dandy function I banged out today for Drupal to reorder a tree taxonomy in alphabetical order.
function reordertaxonomy($tid) {
$sql = 'SELECT term_data.tid, name, weight FROM term_data JOIN term_hierarchy ON term_hierarchy.tid = term_data.tid WHERE term_hierarchy.parent = ' . $tid;
$result = db_query($sql);
if ($result) {
$neworder = array();
while ($row = db_fetch_object($result)) {
$neworder[$row->name] = $row->tid;
reordertaxonomy($row->tid);
}
ksort($neworder);
print_r($neworder);
$i = 0;
foreach ($neworder as $termid) {
$updatesql = 'UPDATE term_data SET weight = "' . $i . '" WHERE tid = "' . $termid . '"';
db_query($updatesql);
$i++;
}
}
}
