Sorting Tags Alphabetically

Hey there,

is there a way of sorting Tags alphabetically?

I’m trying to sort all my clients…

 <?php foreach ($page->clients()->split(', ') as $category): ?>
  <?= $category ?>
  <?php endforeach ?>

Thanks in advance!

$page->clients()->split(', ')

gives you an array with you can then sort with any PHP’s sort functions:

$tags = $page->clients()->split(', ');
sort($tags);

foreach($tags as $category) {
  // do stuff
}

https://www.php.net/manual/de/function.sort.php
The sort function accepts different flags as second argument.

1 Like

Thank you!

I solved my problem and used implode to seperate the items in the array.

<?php
$tags = $page->productions()->split(', ');
sort($tags);
echo implode(', ', $tags);
?>