Saving checkboxes in wordpress custom post type

Hi I have checkboxes defined as such:

"languages" => array("name" => "languages",
"title" => "Languages","description" => "",
"style" => "checkboxes","options" => array("1" => "option1","2" => "option2")),

they display fine using:

Read More
foreach($meta_box['options'] as $radio_value) { 
echo '<input type="checkbox" name="'.$meta_box['name'].'_value'.'"
value="'.$radio_value.'"'; if ($meta_box_value == $radio_value) { echo ' 
checked="yes"'; } echo '/> '.$radio_value. '<br/>';

Now I need to save them.

I am using this code to save all the other fields, but naturally it will only save the last checked checkbox:

if(get_post_meta($post_id, $meta_box['name'].'_value') == "")
   add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
   update_post_meta($post_id, $meta_box['name'].'_value', $data);
elseif($data == "")
  delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));

How would i fix this to save all the checked checkboxes.

Thanks in advance for any help

Related posts

Leave a Reply

1 comment