2017-10-30 11 views
0

警告メッセージ:注意:未定義のインデックスsave_postは、他の時にトリガすることができるので、ライン194CPTに追加のメタボックスと警告メッセージ

Metaboxデータを保存し、これを検証は、私たちの画面から、適切な承認となりました。

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

ここにはありません。どうしたの? –

答えて

0

あなたのケースの「未定義インデックス」は、'team_meta_nonce'がPOST配列にないことを意味します。

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

問題を解決し、メッセージ自体を削除します。ポスト配列に 'team_meta_nonce'を実装します。 – Ashif

0

変更はアクション、あなたが私はあなたのカスタムポストタイプ名は「チーム」

が、その後フックを保存することであると仮定し、ここで

を使用している:それは最初のセットの場合は、確認するためにチェックする必要がありますメタボックスは

add_action('save_post_team', 'rs_save_team_meta', 1, 2); 
関連する問題