Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am playing with custom meta boxes within WordPress and when trying to modify a drop down menu and saving the option it doesn't save.

If I use the default template it saves the option fine.

case 'select':
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
foreach ($field['options'] as $option) {
echo '<option value="', $option['value'], '"', $meta == $option['value'] ? ' selected="selected"' : '', '>', $option['name'], '</option>';
}
echo '</select>';
break;

Below is my modified version to allow 3 drop menus to be displayed:

case 'champbans':
echo '<select name="', $field['id'], '_team1ban_1" id="', $field['id'], '_team1ban_1">';
foreach ($field['options'] as $option1) {
echo '<option value="', $option1['value'], '_team1ban_1"', $meta == $option1['value'] ? ' selected="selected"' : '', '>', $option1['name'],  '</option>';
}
echo '</select>';
echo '<select name="', $field['id'], '_team1ban_2" id="', $field['id'], '_team1ban_2">';
foreach ($field['options'] as $option2) {
echo '<option value="', $option2['value'], '_team1ban_2"', $meta == $option2['value'] ? ' selected="selected"' : '', '>', $option2['name'], '</option>';
}
echo '</select>';
echo '<select name="', $field['id'], '_team1_3" id="', $field['id'], '_team1_3">';
foreach ($field['options'] as $option3) {
echo '<option value="', $option3['value'], '_team1ban_3"', $meta == $option3['value'] ? ' selected="selected"' : '', '>', $option3['name'], '</option>';
}
echo '</select>';
break;

There are no errors being displayed and I can not spot the error after spending the past 2 hours looking at it. Any help or guidence is much appreciated.

share|improve this question
    
could you post the rest of the code to give us some context? What is $field, for example? What is $meta? –  Stephen Harris Feb 6 '12 at 13:26
    
Here is the full metabox code - pastebin.com/hzPuxsFM The code I referenced starts at line 369 –  Dan Whiteside Feb 6 '12 at 13:32

1 Answer 1

up vote 0 down vote accepted

Dan, the problem is that when you save the post meta, it's using a name that doesn't exist as you've added '_team1ban_1 etc, but the code you've linked to looks for inputs named $fields['id'].

If you want to use the linked framework, I suggest you add them as separate fields. (i.e. three separate select boxes). Exactly how to do that falls out of the scope of this site, but a quick look at the pastie, it seems you'll want to add three arrays to the fields (see line 43 for example).

share|improve this answer
    
It was me just trying to cut a corner I think, I just wanted all the selects side by side instead of underneath each other. I have an idea to amend the table that is created for the metabox to work position the elements. –  Dan Whiteside Feb 6 '12 at 14:25

Your Answer

 
discard

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.