I am trying to create a multi-select category list in a theme options page and everything shows up but when i save the options only the last option from the multi-select box that is selected gets saved to the database.
Does someone know what I'm doing wrong perhaps?
Here's bits and pieces of the code I'm currently using:
<?php
$themename_themename = "themename";
$themename_shortname = "themename";
$themename_option_group = $themename_shortname.'_theme_option_group';
$themename_option_name = $themename_shortname.'_theme_options';
// WordPress Categories via an Array
$wp_cats = array();
$categories = get_categories('hide_empty=0&orderby=name');
foreach ($categories as $category_list) {
$wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}
$categories_tmp = array_unshift($wp_cats, "Select a category:");
// Create theme options
global $themename_settings;
$themename_settings = array (
// Multi-select
array( "name" => __( 'Cat List','themename'), 'id' => $themename_shortname.'_list_cats', 'type' => 'multi-select',
"desc" => __( 'Multi Select Unorderd Lists in content area.','themename'),
'std' => '',
"value" => $wp_cats ),
);
function themename_settings_page() {
case 'multi-select': // Multi-select ?>
<div class="options_input options_select">
<div class="options_desc"><?php echo $value['desc']; ?></div>
<span class="labels"><label for="<?php echo $themename_option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>
<select name="<?php echo $themename_option_name.'['.$valueid.']'; ?>" id="<?php echo $themename_option_name.'['.$valueid.']'; ?>" multiple="multiple" style="height:150px; min-width: 200px;">
<?php
$multi_setting = $options[$valueid];
foreach ($value['value'] as $category_list) {
?>
<option value="<?php echo $category_list ?>" <?php if($multi_setting != '') { selected($options[$valueid] == $category_list );} else { selected($options[$valueid] == $value['std']);} ?>><?php echo $category_list; ?></option>
<?php } ?>
</select>
</div>
<?php
break;
} // --themename_settings_page
Here is a temp. screenshot of what is going on: Screenshot
Any help would be very appreciated.