I have a custom post type that is working well and displaying/saving all the text fields. The issue is now I need to add 4 check boxes but not sure how to do that. Any ideas?
function fitter_info() {
global $post;
//Fitter Meta
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="fittermeta_noncename" id="fittermeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
// Get the fitter data if its already been entered
$phone = get_post_meta($post->ID, '_phone', true);
// Echo out the fields
echo '<input type="text" placeholder="Phone" name="_phone" value="' . $phone . '" class="widefat" style="width:40%; margin:5px 20px;" />';
echo '<br><br>';
//The Checkboxes
echo '<label> JR. Fitter </label><input style="margin:0 10px;" type="checkbox" name="fittermeta"id="meta-checkbox" value="jr" />';
echo '<label> Full Fitter </label><input style="margin:0 10px;" type="checkbox" name="fittermeta" id="meta-checkbox" value="full"/>';
echo '<label> Master Fitter </label><input style="margin:0 10px;" type="checkbox" name="fittermeta" id="meta-checkbox" value="master"/>';
echo '<label> Award Winning Fitter </label><input style="margin:0 10px;" type="checkbox" name="fittermeta" id="meta-checkbox" value="award"/>';
}
// Save the Metabox Data
function wpt_save_events_meta($post_id, $post) {
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['fittermeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// OK, we're authenticated: we need to find and save the data
// We'll put it into an array to make it easier to loop though.
$fitters_meta['_phone'] = $_POST['_phone'];
// Add values of $events_meta as custom fields
foreach ($fitters_meta as $key => $value) { // Cycle through the $events_meta array!
if( $post->post_type == 'revision' ) return; // Don't store custom data twice
$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
update_post_meta($post->ID, $key, $value);
} else { // If the custom field doesn't have a value
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
}
}
add_action('save_post', 'wpt_save_events_meta', 1, 2); // save the custom fields