WordPress.org

Support

Support » Themes and Templates » foreach not working

foreach not working

  • Hi, I have a strange problem with using a foreach loop for showing tags. The code from the codex works fine on my local copy (with PHP 5.2.1), but on the public site (PHP 5.2.0) kinda mashes the elements together.

    So using this code:

    foreach($posttags as $tag) {
    echo "tag: ";
    echo $tag->name . ', ';
    }

    Would output:
    tag: tag1 tag2 tag3,

    But locally, I would get what I expect:
    tag: tag1, tag: tag2, tag: tag3,

    Any clues on how I can do this differently to get around it? I tried for & while loops, but couldn’t get it to iterate through the array.

  • The topic ‘foreach not working’ is closed to new replies.
Skip to toolbar