0

Warning Message: Notice: Undefined index: team_meta_nonce in /home/rainpeyi/public_html/wp-content/themes/rainastudio/lib/team_reg.php on line 194

Save the Metabox Data and verify this came from the our screen and with proper authorization, because save_post can be triggered at other times.

function rs_save_team_meta($post_id, $post) {

    if ( !wp_verify_nonce( $_POST['team_meta_nonce'], plugin_basename(__FILE__) )) {
        return $post->ID;
    }

    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
         return;
    }

    // Is the user allowed to edit the post or page
    if ( !current_user_can( 'edit_post', $post->ID )) {
        return $post->ID;
    }


// OK, we're authenticated: we need to find and save the data

// We'll put it into an array to make it easier to loop though.


    $team_meta['_position'] = $_POST['_position'];
    $team_meta['_availability'] = $_POST['_availability'];
    $team_meta['_experience'] = $_POST['_experience'];
    $team_meta['_email'] = $_POST['_email'];

    // Add values of $team_meta as custom fields

    foreach ($team_meta as $key => $value) { // Cycle through the $team_meta array!
        if( $post->post_type == 'revision' ) return; // Don't store custom data twice
        $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
        if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
            update_post_meta($post->ID, $key, $value);
        } else { // If the custom field doesn't have a value
            add_post_meta($post->ID, $key, $value);
        }
        if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
    }

}

add_action('save_post', 'rs_save_team_meta', 1, 2); // save the custom fields
Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
Ashif
  • 13
  • 6

2 Answers2

0

'Undefined index' in your case means that there is no 'team_meta_nonce' in the POST array. You should check to see if it's set first:

if ( !isset($_POST['team_meta_nonce']) || !wp_verify_nonce( $_POST['team_meta_nonce'], plugin_basename(__FILE__) )) {
    return $post->ID;
}
Spartacus
  • 1,468
  • 2
  • 15
  • 29
  • It solves the problem and message remove itself. I implement 'team_meta_nonce' in the post array. – Ashif Oct 31 '17 at 21:52
0

change the action you have used here

I suppose that your custom post type name is "team"

then the hook to save the meta box will be

add_action('save_post_team', 'rs_save_team_meta', 1, 2);
Rajkumar Gour
  • 1,131
  • 12
  • 26