get_option returns undesired blank instance of a widget

I am presently trying to call the fields of a custom widget using get_option and loop through the array created from the get_option() call. The issue is that it is outputting a blank one at the end, resulting in one extra than what I have enabled. Here is the code I have at the moment:

            $the_team = get_option('widget_jcMeetTeam');
            $the_id = 1; //used for an ID increment for the jquery this will be used for
            print_r ($the_team);
    if (count($the_team) > 1) {
            foreach ($the_team as $team_member) {
                    extract($team_member);

                            echo '<div class="panel" id="'.$the_id.'">
                            <img src="'.get_bloginfo('template_url').'/images/about_lgplace.png">
                            <h2>'.$team_member['jc_name'].'</h2>;
                            <p>Occupation: '.$team_member['jc_occupation'].'</p>
                            <p>Favorite Wine: '.$team_member['jc_favwine'].'</p>
                            <p>About: '.$team_member['jc_about'].'</p>
                            </div> ';
                    ++$the_id; //increment for next panel ID
            }
    } 

I am presently trying to figure out how to get the loop to stop before the last blank one gets displayed, giving an accurate listing of active widget instances.

Related posts

Leave a Reply

2 comments

  1. No further help is needed.

    unset($the_team[‘_multiwidget’]); worked, and was the element in the array that was showing up at the end of the call.

    Will have to research what that part is exactly for future reference.

  2. I think the issue is due to an empty record in the database.

    You can verify if $team_member is empty. Add the following before extract($team_member);:

    if( empty($team_member) ) continue;
    

    If $team_member is empty, the code after this will not be run.