June 12, 201313 yr I'm trying to create repeatable select boxes (on the Wordpress admin page) and having a bit of a problem. It seems my i++ is not working and I am only able to save a single value. I didn't include the variable definations but I think they are fairly self-explanitory. case 'home_player_list': echo '<a class="repeatable-add button" href="#">+</a> <ul id="'.$field['id'].'-repeatable" class="custom_repeatable">'; $post_id = get_the_ID(); $team_id = get_post_meta( $post_id, 'report_home-select'); $items = get_users( array ( 'meta_key' => 'team-meta', 'meta_value' => $team_id )); $i = 0; if ($meta) { foreach($meta as $row) { echo '<li><span class="sort hndle button">|||</span>'; echo '<select name="'.$field['id'].'['.$i.']" class="chzn-select" style="width:200px;" id="report_home-scorers"> <option value="">Select One</option>'; // Select One foreach($items as $item) { echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->display_name.'</option>'; } echo '</select><a class="repeatable-remove button" href="#">-</a></li>'; $i++; } } else { echo '<li><span class="sort hndle button">|||</span>'; echo '<select name="'.$field['id'].'['.$i.']" class="chzn-select" style="width:200px;" id="'.$field['id'].'"> <option value="">Select One</option>'; // Select One foreach ($items as $item) { echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->display_name.'</option>'; } echo '</select><a class="repeatable-remove button" href="#">-</a></li>'; } echo '</ul><span class="description">'.$field['desc'].'</span>'; break; It works just fine when I use an imput field but I can't save more than one value in an array. What I'm aiming for is an array of id numbers. If anyone can see offhand what I've done wrong, I'd be very grateful.
June 13, 201313 yr Author In case anyone is curious: Turns out my javascript needed fixing. I was cloning the field and not incrementing it correctly. Also I had $meta == $item->ID ? ' selected="selected"' : instead of $row == $item->ID ? ' selected="selected"' :
Create an account or sign in to comment