Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress自定义帖子类型+;metabox不';不要保存数据_Wordpress_Custom Post Type_Meta Boxes - Fatal编程技术网

Wordpress自定义帖子类型+;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

当我保存post时,metabox中的数据不会保存在数据库中…错误在哪里

我的代码位于:


谢谢

实际上,您已经在
餐厅数据表单
函数中声明了
$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');