Forums

[resolved] [Plugin: Tag Images] Tip to solve error: Invalid argument supplied for foreach() (2 posts)

  1. phirst
    Member
    Posted 2 years ago #

    Hi

    First, thanks for a useful little plug-in.

    (I'm a competent user, but know little about php)

    I used the function: foreach(get_tag_image as $tag) echo get_tag_image($tag) in my post, however, if a post did not have any tags associated with it I got the error Invalid argument supplied for foreach() ...

    Anyway, after some searching and figuring out some php, to which I'm new, I ended up adding the following codes instead, to evaluate an if statement first to check there were any tags before getting to the foreach statement, as follows:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) echo get_tag_image($tag);
    }
    ?>

    Which seems to work fine.

    - Just wanted to post this here to help anyone else who might pick up this error and want to fix it. Or if anyone else has a better/simpler way to fix they can advise...

    http://wordpress.org/extend/plugins/tag-images/

  2. chrisnorthwood
    Member
    Posted 2 years ago #

    I suspect your issue was actually due to missing the () off the get_the_tags function.

    Regards,

    Chris Northwood

Topic Closed

This topic has been closed to new replies.

About this Topic