Created
February 12, 2015 18:57
-
-
Save LinzardMac/461a47865eb1394c310b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* the lines of code that generates ALL checkbox fields*/ | |
case 'checkbox': | |
echo '<input type="checkbox" name="'.$field['id'].'" class="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/> | |
<label for="'.$field['id'].'">'.$field['desc'].'</label>'; | |
break; | |
/* the actual HTML output seems the same */ | |
<tr> | |
<th><label for="custom_multiday">Multi-Day</label></th> | |
<td><input type="checkbox" name="custom_multiday" class="custom_multiday" id="custom_multiday" checked="checked"> | |
<label for="custom_multiday"></label></td></tr> | |
<tr><!-- only this field actually saves the OFF status --> | |
<th><label for="custom_recurring">Recurring</label></th> | |
<td><input type="checkbox" name="custom_recurring" class="custom_recurring" id="custom_recurring" checked="checked"> | |
<label for="custom_recurring"></label></td></tr> | |
<tr> | |
<th><label for="custom_cost_free">Free Admission? </label></th> | |
<td><input type="checkbox" name="custom_cost_free" class="custom_cost_free" id="custom_cost_free" checked="checked"> | |
<label for="custom_cost_free">Check box if admission if free</label></td></tr> | |
/* code for the saving (truncated) */ | |
// loop through fields and save the data | |
foreach ($custom_meta_fields as $field) { | |
if(isset($_POST[$field['id']])){ | |
$old = get_post_meta($post_id, $field['id'], true); | |
$new = $_POST[$field['id']]; | |
if ($new && $new != $old) { | |
update_post_meta($post_id, $field['id'], $new); | |
} elseif ('' == $new && $old) { | |
delete_post_meta($post_id, $field['id'], $old); | |
} | |
}elseif(!isset($_POST[$field['id']])){ | |
// this deletes the value if the field has nothing in it. | |
delete_post_meta($post_id, $field['id'], $old); | |
}// end if isset | |
} // end foreach | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment