警告メッセージ:注意:未定義のインデックス
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
ここにはありません。どうしたの? –