The code i'm using to save my custom meta boxes isn't working at all, can you tell me where i've gone wrong? At the moment it's only saving one radio button, hence why there's only one entry in the array.
Thanks
function save_nwt_home_section_settings_meta($post_id, $post) {
// 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.
$nwt_home_section_settings_array['nwt_home_section_header_io'] = $_POST['nwt_home_section_header_io'];
// Add values of $events_meta as custom fields
foreach ($nwt_home_section_settings_array as $key => $value) { // Cycle through the $events_meta array!
if( $post->post_type == 'revision' ) return; // Don't store custom data twice
update_post_meta($post->ID, $key, $value);
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
}
}
add_action('save_post', 'save_nwt_home_section_settings_meta', 1, 2); // save the custom fields
Aucun commentaire:
Enregistrer un commentaire