WordPress.org

Ready to get started?Download WordPress

Forums

Tags (2 posts)

  1. archi27
    Member
    Posted 1 year ago #

    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?

  2. vtxyzzy
    Member
    Posted 1 year ago #

    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>";
          }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags