Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.