• Someone help me on how to display tags in ANY alphabetical order.

    I used this code for displaying only the first tag:

    ?php
    $posttags = get_the_tags();
    $count=0;
    if ($posttags) {
    foreach($posttags as $tag) {
    $count++;
    if (1 == $count) {
    echo $tag->name . ‘ ‘;
    }
    }
    }
    ?>

    Any help guys?

Viewing 1 replies (of 1 total)
  • Try this:

    <?php
          $posttags = get_the_tags();
          usort($posttags, function($a, $b) {
             return strcasecmp($a->name, $b->name);
             });
          foreach ($posttags as $tag) {
             echo "<p>SORTED:$tag->name</p>";
          }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Tags’ is closed to new replies.