Wordpress自定义帖子类型+ metabox不保存数据
答
其实你已经宣布你$rest_custom_meta_fields
阵列内restaurant_data_form
功能,并尝试使用它在save_restaurant_custom_meta
功能,在这种情况下,数组是出了功能范围,使foreach ($rest_custom_meta_fields as $field)
是行不通的。
为了克服这个问题,你可以保持阵列出你restaurant_data_form
,就像
$rest_custom_meta_fields = array(
array(
'label'=> 'Address',
'desc' => 'Plugin use it to get map',
'id' => $prefix.'text_address',
'type' => 'text'
),
...
);
的restaurant_data_form
函数前面,并在你的restaurant_data_form
功能
function restaurant_data_form()
{
$prefix = 'rest_';
global $post, $rest_custom_meta_fields;
// ...
}
所以应该申报array
看起来像这样(该阵列在全球范围内)
$rest_custom_meta_fields = array(
array(...),
...
);
function restaurant_data_form()
{
$prefix = 'rest_';
global $post, $rest_custom_meta_fields;
// ...
}
我希望这能解决问题。此外,在你的代码你到底有没有使用
echo add_action('save_post', 'save_restaurant_custom_meta');
从add_action(...)
声明的开头删除的echo
。
It works !!! Thanks !!! – aquanat 2013-05-15 12:27:46