im having a metabox in wordpress with a mutliple select form.
adding [] to the name
was correct, however I allso needed to replace the following save line:
update_post_meta( $post_id, 'my_meta_box_select', esc_attr( $_POST['my_meta_box_select'] ) );
with the following:
update_post_meta($post_id, 'my_meta_box_select', array_map( 'strip_tags', $_POST['my_meta_box_select'] ) );
Thanks alot for the assistance Nate!
Often overlooked, super simple.
The name attribute needs to allow for multiple selections to be sent over $_POST
as an array. For example:
<select name="my_meta_box_select[]" id="my_meta_box_select" multiple="" style="width:300px; height:400px;">
<option value="red">Red
</option>
<option value="blue">Blue
</option>
</select>
Notice the []
in the name: name="my_meta_box_select[]"
This, alongside the multiple
attribute, will allow your $_POST
variable to contain all selections as an array. That said, $_POST['my_meta_box_select']
will not just be a simple value, but rather will be an array will all selections.