WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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
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


share|improve this answer

Your Answer


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.