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 have created a new custom post type and some custom fields for it. My function for saving the custom meta fields fires on the 'save_post' hook.

The problem is that I am getting a warning when I go to add a new post:

Notice: Undefined index: my_meta_box_nonce....

       // verify nonce
    if ( ! wp_verify_nonce( $_POST[ 'my_meta_box_nonce' ], basename( __FILE__ ) ) ) 
       return $post_id; 

When I enter the post details and hit publish the error is not displayed, it's only there when I create a new empty post. What's wrong here?

My code is almost identical and based on this tutorial: http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/

In the comments of that tutorial it seems that there were others who had the same problem, but there is no solution given.

share|improve this question
up vote 0 down vote accepted

I know that this is not the only tutorial that has code that check nonce for meta boxes but this is truly idiotic. Nonce should be checked per the whole action not per parts of it and if your save_post hook was called it means that the save nonce was already checked and found valid, so There is no need for more security checks.

My advice is to simply remove anything related to nonce from your metabox code, but if you will feel better having it around just change the code to

   // verify nonce
    if ( !isset($_POST[ 'my_meta_box_nonce' ]) || !wp_verify_nonce( $_POST[ 'my_meta_box_nonce' ], basename( __FILE__ ) ) ) 
       return $post_id; 

which will bail out when no nonce was supplied or the nonce failed validation

share|improve this answer
If I use that code the metaboxes aren't saved, although the notices mentioned don't show any more. – drtanz Feb 25 '13 at 3:31

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.