Q:

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:
<?php foreach($data as $tid => $name): ?>
<div data-filter=".filter-<?php print $tid; ?>" class="cbp-filter-item">
  <?php print $name; ?>
  <?php print $text_counter; ?>
</div>
<?php endforeach; ?>

How can I sort the taxonomy terms by their tids?

A:

Base on your code, I think the key for the $data is tid.
You can just add <?php ksort($data);?> before your foreach loop.

