Alphabetically Sort Terms of Taxonomy
- سُلَيْمَان بْن دَاوُوْد

- Jun 11, 2021
- 1 min read

<?php
function cmp($a, $b){
return strcmp($a->slug, $b->slug);
}
$terms = get_terms([
'taxonomy' => 'product_brand',
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC'
]);
usort($terms, "cmp");
foreach($terms as $term){
?>
<li>
<input type="radio" id="<?php echo $term->slug; ?>" name="brand" value="<?php echo $term->slug; ?>"
class="prdfilter">
<label for="<?php echo $term->slug; ?>"><?php echo $term->name; ?></label>
</li>
<?php } ?>',
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC'
]);
usort($terms, "cmp");
foreach($terms as $term){
?>
<li>
<input type="radio" id="<?php echo $term->slug; ?>" name="brand" value="<?php echo $term->slug; ?>"
class="prdfilter">
<label for="<?php echo $term->slug; ?>"><?php echo $term->name; ?></label>
</li>
<?php } ?>
Comments