WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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) {

                            echo '<div class="panel" id="'.$the_id.'">
                            <img src="'.get_bloginfo('template_url').'/images/about_lgplace.png">
                            <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.

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
Thank you for the help Sorich87, but that didn't end up helping. My manager suggested unset for the array element that kept showing up at the end, which was "_multiwidget" Seems to have done the trick, and I forgot to post that bit in my original question. Once again thanks for the help attempt. – tw2113 Oct 26 '10 at 17:26
You are welcome! – sorich87 Oct 26 '10 at 18:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.