Before WordPress 4.4 recent update, I was able to create an array instance in a widget from a multiple select menu this way:
<?php $cats = get_categories(); ?>
<select multiple="multiple" name="<?php echo $this->get_field_name('cats][') ?>">
<?php foreach ( $cats as $cat ) { ?>
<option value="<?php echo $cat->term_id ?>"><?php echo $cat->name; ?></option>
<?php } ?>
</select>
The type of $instance['cats']
generated from this code was an array before that update, now it's a string.
What has changed and how can I solve it?
=======
UPDATE: Complete code of a widget:
###################################################################
function widet_sample() {
register_widget('widet_sample');
}
add_action('widgets_init', 'widet_sample');
class widet_sample extends WP_Widget {
function widet_sample() {
parent::__construct(false, 'SAMPLE');
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['cats'] = $new_instance['cats'];
return $instance;
}
function form($instance) {
?>
<p>
Categories IDs: <?php print_r($instance['cats']); ?>
</p>
<p>
<?php $cats = get_categories(); ?>
<select class="widefat" multiple="multiple" name="<?php echo $this->get_field_name('cats][') ?>">
<?php foreach ( $cats as $cat ) { ?>
<option value="<?php echo $cat->term_id ?>"><?php echo $cat->name; ?></option>
<?php } ?>
</select>
</p>
<?php
}
}
###################################################################
$instance['cats']
at all. Please post the code in enough context that the problem can be duplicated.][
in your field name? That looks a bit hackish and it looks like the kind of thing that could (should) get sanitized away.<select multiple="multiple" name="options_group[field_name][]">
in my theme options file.