Wordpress自定义帖子类型+;metabox不';不要保存数据
当我保存post时,metabox中的数据不会保存在数据库中…错误在哪里 我的代码位于:Wordpress自定义帖子类型+;metabox不';不要保存数据,wordpress,custom-post-type,meta-boxes,Wordpress,Custom Post Type,Meta Boxes,当我保存post时,metabox中的数据不会保存在数据库中…错误在哪里 我的代码位于: 谢谢 实际上,您已经在餐厅数据表单函数中声明了$rest\u custom\u meta\u字段数组,并试图在保存餐厅自定义元函数中使用它,在这种情况下,数组超出了函数范围,因此foreach($rest\u custom\u meta\u fields as$field)不起作用 要解决此问题,您可以将数组保留在餐厅数据表单之外,只需在餐厅数据表单函数之前声明数组 $rest_custom_meta_fi
谢谢 实际上,您已经在
餐厅数据表单
函数中声明了$rest\u custom\u meta\u字段
数组,并试图在保存餐厅自定义元
函数中使用它,在这种情况下,数组超出了函数范围,因此foreach($rest\u custom\u meta\u fields as$field)
不起作用
要解决此问题,您可以将数组保留在餐厅数据表单
之外,只需在餐厅数据表单
函数之前声明数组
$rest_custom_meta_fields = array(
array(
'label'=> 'Address',
'desc' => 'Plugin use it to get map',
'id' => $prefix.'text_address',
'type' => 'text'
),
...
);
在您的餐厅\u数据\u表单中
函数
function restaurant_data_form()
{
$prefix = 'rest_';
global $post, $rest_custom_meta_fields;
// ...
}
所以它应该是这样的(数组在全局范围内)
我希望这能解决问题。在代码的末尾,您也使用了
echo add_action('save_post', 'save_restaurant_custom_meta');
从add_action(…)
语句的开头删除echo
echo add_action('save_post', 'save_restaurant_custom_meta');