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:
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
Here’s a helpful link on creating meta boxes: http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/.
You might end up tossing what you currently have, but I employ this method on my own blogs and it works quite well.