Using Wordpress I've produced a multiple choose box to ensure that customers can choose groups to exclude. Once the page initially loads I see my default values pre-selected. However, if I choose new values and save... I only begin to see the word "Array" echoed and absolutely nothing selected?

<select class="amultiple" id="<?php echo $value['id']; ?>"  name="<?php echo $value['id']; ?>[]" multiple="multiple" size="8">
    			global $options;
    				foreach ($options as $value) {
    					if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); 
    				$categories = &get_categories('type=post&orderby=name&hide_empty=1');
    				if ($categories) {
    					$ex_cat = implode(',', $tt_cat_exclude);

    					foreach ($categories as $category) {
    						$selected = (in_array($ex_cat, $category->cat_ID)) ? ' selected="selected"' : '';
    						echo '<option value="' . $category->cat_ID . '"' . $selected . '>' . $category->cat_name . '</option>' . "\n";
<br />For testing purposes, print variables: <?php echo $ex_cat; ?>

Appears like tt_cat_exclude is missing it's opening $

title="tt_cat_exclude[]" means you are determining an assortment, therefore it is normal for that output to become "array"

for testing try print_r (results the entire architecture from the variable) or var_dump (results the var type too)

Whenever you postback, the area tt_cat_exclude is a range of the values that you have set - because you have title it tt_cat_exclude[] having a [] behind.


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select class="amultiple" id="tt_cat_exclude"  name="tt_cat_exclude[]" multiple="multiple" size="8">
  <option value="1">TestingA</option>
  <option value="2">TestingB</option>
  <option value="3">TestingC</option>
  <option value="4">TestingD</option>
  <option value="5">TestingE</option>
<input type="submit" value="Submit" />
<br/><br/>For testing purposes: <?php

  var_dump($_POST['tt_cat_exclude']); // outputs an array of the selected values


You need to use implode()

Like so

$ex_cat = implode(',', $tt_cat_exclude);

This can return a comma separated list

This line ought to be

$selected = (in_array($category->cat_ID, $ex_cat)) ? ' selected="selected"' : '';

Transformed to

$selected = (in_array($category->cat_ID, $tt_cat_exclude)) ? ' selected="selected"' : '';

Because the $ex_cat is really a string and can't be utilized in in_array()

The $ex_cat has become redundant i suppose.