WordPress.org

Support

Support » Plugins and Hacks » get_the_tags() problems

get_the_tags() problems

  • Hi Guys,

    I am using this code to get some tags for a post

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach ($posttags as $tag) {
         $tagnames[count($tagnames)] = $tag->name;
      }
      $comma_separated_tagnames = implode(", ", $tagnames);
      print_r($comma_separated_tagnames);
    }
    ?>

    The problem i am facing when i use this code is that tags are “aggregated” i.e. it prints tags at the top post fine – only the top post tags appear, but then in the 2nd post – it prints the top post tags and the second post tags and so on. third post, 1st, 2nd and 3rd post tags etc etc how to restrict tags in this code, to just show for one post ?

    i.e. this code works perfect from the get_tags() page

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    echo $tag->name . ' ';
    }
    }
    ?>

    and it returns only the tags for each post. The code I am using works great since I can print echo $comma_separated_tagnames but I’m not a PHP coder so not sure how to change the code to not make to “count up / aggregate” the tags – and instead just show tags per individual post ?

    Please help?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_the_tags() problems’ is closed to new replies.