zxprince
zxprince

Reputation: 387

wordpress - POST multiple select value as an array for custom meta box

I am using wordpress 3.5. I create a custom post type and a custom metabox where i use a html multi select menu

<select data-placeholder="Choose available colors..." class="chosen_multi" name="available_colors[]" id="available_colors" multiple="multiple">
....
....
</select>

i use bellow code to save select value

update_post_meta($id, 'available_colors', strip_tags($_POST['available_colors']));

But i know it not store multi value as array in Database.

How i store array (available_colors[]) by update_post_meta, Not want to use php implode explode

Upvotes: 0

Views: 3035

Answers (1)

C. E.
C. E.

Reputation: 10607

If you store an array with update_post_meta, get_post_meta will return an array. It's that simple.

However, if $_POST['available_colors'] is an array, you can't use strip_tags on it. Instead you would have to use strip_tags on every element:

update_post_meta($id, 'available_colors', array_map( 'strip_tags', $_POST['available_colors'] ) );

Upvotes: 1

Related Questions