自定义的栏目,在快速编辑中老出问题,求解
wordpress吧
全部回复
仅看楼主
level 1
轩辕文博 楼主
自定义的栏目,在快速编辑中老出问题,求解
2013年11月21日 09点11分 1
level 1
轩辕文博 楼主
先给大家看下我的代码:
add_action('admin_menu', 'create_meta_box');
//在加载管理员界面界面的时候调用create_meta_box函数
add_action('save_post', 'save_postdata');
function create_meta_box(){
if(function_exists('add_meta_box')){
//add_meta_box函数在文章编辑页面内添加版块,具体用法放在文章最后
add_meta_box('new-meta-box','自定义模块','new_meta_box','post','normal','high');
//此函数调用new_meta_box函数
}
}
function new_meta_box(){
global $post;
$meta_box_value = get_post_meta($post->ID, 'pro_pic', true);
echo '<h4>产品图片</h4>';
wp_editor(str_replace('\"','"',$meta_box_value), 'pro_pic', $settings = array(quicktags=>1,
tinymce=>1,
media_buttons=>0,
textarea_rows=>4,
editor_class=>"textareastyle") );
$meta_box_value_chisan = get_post_meta($post->ID, 'chisan', true);
echo '<h4>尺寸与散热</h4>';
wp_editor(str_replace('\"','"',$meta_box_value_chisan), 'chisan', $settings = array(quicktags=>1,
tinymce=>1,
media_buttons=>0,
textarea_rows=>4,
editor_class=>"textareastyle") );
$meta_box_value_guangcanshu = get_post_meta($post->ID, 'guangcanshu', true);
echo '<h4>光参数</h4>';
wp_editor(str_replace('\"','"',$meta_box_value_guangcanshu), 'guangcanshu', $settings = array(quicktags=>1,
tinymce=>1,
media_buttons=>0,
textarea_rows=>4,
editor_class=>"textareastyle") );
}
function save_postdata($post_id){
global $post;
$data_pic = wpautop($_POST['pro_pic']);
$data_chisan=wpautop($_POST['chisan']);
$data_guangcanshu=wpautop($_POST['guangcanshu']);
if(get_post_meta($post_id,'pro_pic') == "")
add_post_meta($post_id,'pro_pic', $data_pic, true);
elseif($data_pic != get_post_meta($post_id,'pro_pic', true))
update_post_meta($post_id,'pro_pic', $data_pic);
elseif($data_pic == "")
delete_post_meta($post_id,'pro_pic', get_post_meta($post_id,'pro_pic', true));
if(get_post_meta($post_id,'chisan') == "")
add_post_meta($post_id,'chisan', $data_chisan, true);
elseif($data_chisan != get_post_meta($post_id,'chisan', true))
update_post_meta($post_id,'chisan', $data_chisan);
elseif($data_chisan == "")
delete_post_meta($post_id,'chisan', get_post_meta($post_id,'chisan', true));
if(get_post_meta($post_id,'guangcanshu') == "")
add_post_meta($post_id,'guangcanshu', $data_guangcanshu, true);
elseif($data_guangcanshu != get_post_meta($post_id,'guangcanshu', true))
update_post_meta($post_id,'guangcanshu', $data_guangcanshu);
elseif($data_guangcanshu == "")
delete_post_meta($post_id,'guangcanshu', get_post_meta($post_id,'guangcanshu', true));
}
在编辑 发布文章 更新文章的时候都没有问题,就是在快速编辑 的时候,这三个自定义的字段老是变成空的了!
2013年11月21日 09点11分 2
level 1
轩辕文博 楼主
已经解决了!
http://www.4006961899.com/?p=341
大家遇到问题的,可以按这个教程来
2013年11月23日 09点11分 3
1