Я пытался заставить свой метабокс работать, но по какой-то причине всякий раз, когда я помещаю текст и пытаюсь сохранить данные внутри текстового поля, они не сохраняются.
add_action("admin_init", "custom_product_metabox");
function custom_product_metabox(){
add_meta_box("custom_product_metabox_01", "Product Description", "custom_product_metabox_field", "portfolio_page", "normal", "low");
}
function custom_product_metabox_field(){
global $page;
$data = get_post_custom($page->ID);
$val = isset($data['custom_product_input']) ? esc_attr($data['custom_product_input'][0]) : 'no value';
echo '<textarea rows = "5" cols = "220" name = "custom_product_input" id = "custom_product_input" value = "'.$val.'"></textarea>';
}
add_action("save_post", "save_detail");
function save_detail(){
global $page;
if (define('DOING_AUTOSAVE') && DOING_AUTOSAVE){
return $page->ID;
}
update_post_meta($page->ID, "custom_product_input", $_POST["custom_product_input"]);
}
На самом деле это код для страницы портфолио, которую я встроил в functions.php. Есть идеи, как заставить его работать и сохранить данные?
Спасибо!






Ваш метод сохранения выглядит неверным. Попробуйте что-нибудь вроде
function custom_product_metabox_field($post){
//global $page; remove this line also
$data = get_post_custom($post->ID);
$val = !empty(get_post_meta( $post->ID, 'custom_product_input', true )) ?
get_post_meta( $post->ID, 'custom_product_input', true ) : 'no value';
echo '<textarea rows = "5" cols = "220" name = "custom_product_input" id = "custom_product_input" value = "'.$val.'"></textarea>';
}
add_action("save_post", "save_detail", 10, 3 );
function save_detail($post_id, $post, $update){
//global $page;// remove this line
if (define('DOING_AUTOSAVE') && DOING_AUTOSAVE){
return $post_id;
}
update_post_meta($post_id, "custom_product_input", $_POST["custom_product_input"]);
}
по-прежнему не сохраняет данные .. как вы думаете, страница $ актуальна?