How to sort taxonomy terms by their tid? I'm using a custom module to print taxonomy terms as filters inside a View.



I want to sort the taxonomy terms by their tids not by their names.

The below is from the custom-filter.tpl.php:

&lt;?php foreach($data as $tid =&gt; $name): ?&gt;
&lt;div data-filter=".filter-&lt;?php print $tid; ?&gt;" class="cbp-filter-item"&gt;
  &lt;?php print $name; ?&gt;
  &lt;?php print $text_counter; ?&gt;
&lt;/div&gt;
&lt;?php endforeach; ?&gt;


How can I sort the taxonomy terms by their tids?
Base on your code, I think the key for the $data is tid.

You can just add &lt;?php ksort($data);?&gt; before your foreach loop.