--- taxonomy_menu/taxonomy_menu.database.inc	2009-11-19 21:28:05.000000000 +0100
+++ taxonomy_menu_new/taxonomy_menu.database.inc	2011-02-17 12:02:02.000000000 +0100
@@ -127,8 +127,16 @@ function _taxonomy_menu_get_terms($vid) 
  *
  * @param $tid
  */
-function _taxonomy_menu_term_count($tid) {
-  return db_result(db_query(db_rewrite_sql('SELECT COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND t.tid = %d'), $tid));
+function _taxonomy_menu_term_count($tid,&$visited=array()) {
+  if (in_array($tid,$visited)) return 0;
+  $visited[]=$tid;
+  $t=taxonomy_get_term($tid);
+  $count=db_result(db_query(db_rewrite_sql('SELECT COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND t.tid = %d'), $tid));
+  $r=db_query("SELECT tid FROM {term_hierarchy} WHERE parent=%d",$tid);
+  while ($t=db_fetch_object($r)){
+    $count += _taxonomy_menu_term_count($t->tid,$visited);
+  }
+  return $count;
 }
 
 /**
