How can I get the term ID out of the hierarchical select theming function?
The entity is a stdClass object, you need to use the -&gt; accessor:

flag_create_link('hobbies', $term-&gt;$item['#options']['entity']-&gt;tid);