Criar e salvar várias meta-checkboxs

Eu criei um custom-post-type e várias metaboxes que precisam ser salvas. Eu tenho uma function que salva uma metabox, mas não consigo descobrir como reutilizar esta function para salvar todas as metaboxes.

add_action ("add_meta_boxes", "add_dedications_jh"); function add_dedications_jh() { add_meta_box('jh_dedicationDate', 'Enter Date', 'jh_dedicationDate', 'jh_dedications', 'side', 'default'); add_meta_box('jh_dedicationName', 'Enter Name', 'jh_dedicationName', 'jh_dedications', 'normal', 'default'); add_meta_box('jh_dedicationOccasion', 'Enter Occasion', 'jh_dedicationOccasion', 'jh_dedications', 'normal', 'default'); } function jh_dedicationDate($object, $box) { wp_nonce_field( basename( __FILE__ ), 'dedicationDate_nonce' ); ?> <input type="text" name="dedicationDate" value="ID, 'dedicationDate', true) ); ?>" />  <input type="text" size="60" name="dedicationName" value="ID, 'dedicationName', true) ); ?>" />  <input type="text" size="60" name="jh_dedicationOccasion" value="ID, 'dedicationOccasion', true) ); ?>" /> post_type ); /* Check if the current user has permission to edit the post. */ if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; /* Get the posted data and sanitize it for use as an HTML class. */ $new_meta_value = ( isset( $_POST['dedicationDate'] ) ? sanitize_html_class( $_POST['dedicationDate'] ) : '' ); /* Get the meta key. */ $meta_key = 'dedicationDate'; /* Get the meta value of the custom field key. */ $meta_value = get_post_meta( $post_id, $meta_key, true ); /* If a new meta value was added and there was no previous value, add it. */ if ( $new_meta_value && '' == $meta_value ) add_post_meta( $post_id, $meta_key, $new_meta_value, true ); /* If the new meta value does not match the old value, update it. */ elseif ( $new_meta_value && $new_meta_value != $meta_value ) update_post_meta( $post_id, $meta_key, $new_meta_value ); /* If there is no new meta value but an old value exists, delete it. */ elseif ( '' == $new_meta_value && $meta_value ) delete_post_meta( $post_id, $meta_key, $meta_value ); } 

Solutions Collecting From Web of "Criar e salvar várias meta-checkboxs"

Você deve repetir as últimas 9 linhas do seu código para os outros 2 campos não relacionados. Considere a seguinte function

 function wp64123_sanitize_save_meta($nonce_field){ /* Get the posted data and sanitize it for use as an HTML class. */ $new_meta_value = ( isset( $_POST[$nonce_field] ) ? sanitize_html_class( $_POST[$nonce_field] ) : '' ); /* Get the meta key. */ $meta_key = $nonce_field; /* Get the meta value of the custom field key. */ $meta_value = get_post_meta( $post_id, $meta_key, true ); /* If a new meta value was added and there was no previous value, add it. */ if ( $new_meta_value && '' == $meta_value ) add_post_meta( $post_id, $meta_key, $new_meta_value, true ); /* If the new meta value does not match the old value, update it. */ elseif ( $new_meta_value && $new_meta_value != $meta_value ) update_post_meta( $post_id, $meta_key, $new_meta_value ); /* If there is no new meta value but an old value exists, delete it. */ elseif ( '' == $new_meta_value && $meta_value ) delete_post_meta( $post_id, $meta_key, $meta_value ); } 

Agora, você precisa chamar a function acima para cada campo não relacionado.

 wp64123_sanitize_save_meta("dedicationDate"); wp64123_sanitize_save_meta("dedicationName"); wp64123_sanitize_save_meta("dedicationOccassion"); 

Se você estiver enviando e processando o formulário dentro da área de administração WP, então você pode usar check_admin_referer() vez de wp_verify_nonce()

 if ( !empty($_POST) && check_admin_referer('name_of_my_action','name_of_nonce_field') ) { // process form data } 

Leia mais no Codex http://codex.wordpress.org/Function_Reference/wp_nonce_field