【发布时间】:2015-06-23 23:27:28
【问题描述】:
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
【问题讨论】:
标签: php wordpress radio-button