Title: Theme options, select multiple
Last modified: August 19, 2016

---

# Theme options, select multiple

 *  [stevenoi](https://wordpress.org/support/users/stevenoi/)
 * (@stevenoi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/theme-options-select-multiple/)
 * Hi, I got a litle script which display all pages you got in a multiple select
   on a theme options page. So far everything worked, but when I try want to display
   the ‘answers’ of that option I got two problems.
 * 1. I retrieve only 1 of all the options I chosen. E.G. I selected page with ID
   5,3623 and 23. The layout will only show the latest option ( 23 ). I don’t know
   if it’s the Framework, or the code I use to retrieve the options.
    2. I want 
   to display a “,” after each page ID. Not: 5 3623 23. But : 5,3623,23. Like foreach
   orso.
 * FRAMEWORK
 *     ```
       <?php 
   
       function mytheme_add_admin() {
   
       global $themename, $shortname, $options ;
   
       if ( $_GET['page'] == basename(__FILE__) ) {
   
       if ( 'save' == $_REQUEST['action'] ) {
   
       foreach ($options as $value) {
       update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
   
       foreach ($options as $value) {
       if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
   
       header("Location: themes.php?page=theme-options.php&saved=true");
       die;
   
       } else if( 'reset' == $_REQUEST['action'] ) {
   
       foreach ($options as $value) {
       delete_option( $value['id'] ); }
   
       header("Location: themes.php?page=theme-options.php&reset=true");
       die;
   
       }
       }
   
       add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
   
       }
   
       function mytheme_admin() {
   
       global $themename, $shortname, $options;
   
       ?>
   
       <div id="wrap">
   
       <form method="post" action="" >
   
       <?php
       break;
   
       case 'excludepage':
       ?>
   
       <select id="topexclude" name="topexclude" multiple="multiple" style="height:150px;">
       <?php foreach($news_categories as $page) : ?>
       <option name="topexclude" value="<?php echo $page->ID; ?>" <?php if(is_array($val['topexclude']) && in_array($page->ID, $val['topexclude'])) echo ' selected="selected"'; ?>>
       <?php echo $page->post_title; ?>
       </option>
       <?php endforeach; ?>
       </select>
   
       <?php break;
   
       }
       }
       ?>
   
       <p class="submit">
       <input name="save" type="submit" value="Save changes" />
       <input type="hidden" name="action" value="save" />
       </p>
   
       </form>
   
       <?php
       }
       ?>
       ```
   
 * THIS WILL ACTIVE THE EXCLUDEPAGE
 *     ```
       <?php
   
       $options = array (
   
       	array(	"name" => "Layout style",
       		"id" => "topexclude",
       		"desc" => "Click on the pages you want to exclude from the top navigation"
       		"type" => "excludepage" ),
   
       );
       ?>
       ```
   
 * AND THIS CODE I USE TO SHOW EXCLUDEPAGE
 * `<?php echo get_option('topexclude');?>`
 * I think I need some expert help 😛
 * – Steven

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [stevenoi](https://wordpress.org/support/users/stevenoi/)
 * (@stevenoi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/theme-options-select-multiple/#post-1125635)
 * bump…
 *  [blackmesa](https://wordpress.org/support/users/blackmesa/)
 * (@blackmesa)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/theme-options-select-multiple/#post-1125724)
 * I am having the same problem, when I retrieve the value of a select form element
   with multiple values it only returns the last value selected and no others.
 *  [blackmesa](https://wordpress.org/support/users/blackmesa/)
 * (@blackmesa)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/theme-options-select-multiple/#post-1125725)
 * Hah, figured it out moments after i posted this. Here’s were I was going wrong..
 * When you make the select tell it you are going to expect the value as an array
   by putting “[]” at the end of the name parameter.
 * Exampl:
 * <select name=”MySelect[]”>
 * This made it so i got an array returned as my value, although this isn’t the 
   commented list i was expecting it’s actually much easier to use.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Theme options, select multiple’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [blackmesa](https://wordpress.org/support/users/blackmesa/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/theme-options-select-multiple/#post-1125725)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
