Ordering multi word tags by second value

If it’s just an array of plucked values, you can use array_map():

    <?php
    $tags = page('projects')->children()->pluck('tags', ',', true);

    $callback = function($item) {
      $tag = explode(' ', $item);
      return array_reverse($tag);
    };

    $map = array_map($callback, $tags);

    array_multisort($map, SORT_ASC);

    foreach($map as $key => $name) {
      echo $name[1] . ' ' . $name[0];
    }
?>
1 Like