nwt_home_section_header_io我用来保存自定义元框的代码根本不起作用,你能告诉我哪里出了问题吗?目前它只保存一个单选按钮,因此为什么阵列中只有一个条目。
由于
function save_nwt_home_section_settings_meta($post_id, $post) {
// 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.
$nwt_home_section_settings_array = array(
'nwt_home_section_header_io' => $_POST['nwt_home_section_header_io']
);
// Add values of $events_meta as custom fields
foreach ($nwt_home_section_settings_array as $key => $value) { // Cycle through the $events_meta array!
if( $post->post_type == 'revision' ) return; // Don't store custom data twice
update_post_meta($post->ID, $key, $value);
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
}
}
add_action('save_post', 'save_nwt_home_section_settings_meta', 1, 2); // save the custom fields
答案 0 :(得分:2)
Please try somthing like this
$resources = $_POST['authors-commentary-resources'];
$sanitized_resources = array();
foreach ( $resources as $resource ) {
$resource = esc_url( strip_tags( $resource ) );
if ( ! empty( $resource ) ) {
$sanitized_resources[] = $resource;
}
}
update_post_meta( $post_id, 'authors-commentary-resources', $sanitized_resources );
}