How to save multiple metaboxes?

I read a tutorial about metaboxes, most of things are clear but I have a question about multiple metaboxes.

My question is about saving, in the tutorial:

<?php  
add_action( 'save_post', 'cd_meta_box_save' );  
function cd_meta_box_save( $post_id )  
{  
    // Bail if we're doing an auto save  
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; 

    // if our nonce isn't there, or we can't verify it, bail 
    if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return; 

    // if our current user can't edit this post, bail  
    if( !current_user_can( 'edit_post' ) ) return;  
}  
?> 

Do I need to make for example two save functions if I have 2 metaboxes, or can I put the values in same save function? What is the best method? If I render the fields with two different function how to deal with the wp_nonce_field ? What is the best method?

1 Answer
1

You can use one save function.

wp_nonce_field function creates hidden field with action.

You can use wp_nonce_field for two metaboxes if you want different actions for two metaboxes.

Please go throgh below link for more information

http://codex.wordpress.org/Function_Reference/wp_nonce_field

Leave a Comment