【发布时间】:2013-04-24 14:40:46
【问题描述】:
【问题讨论】:
标签: wordpress custom-post-type meta-boxes
【问题讨论】:
标签: wordpress custom-post-type meta-boxes
实际上,您已经在 restaurant_data_form 函数中声明了您的 $rest_custom_meta_fields 数组并尝试在 save_restaurant_custom_meta 函数中使用它,在这种情况下,该数组超出了函数范围,因此 foreach ($rest_custom_meta_fields as $field) 不起作用。
要克服这个问题,您可以将数组排除在您的 restaurant_data_form 之外,只需在 restaurant_data_form 函数之前声明 array 即可
$rest_custom_meta_fields = array(
array(
'label'=> 'Address',
'desc' => 'Plugin use it to get map',
'id' => $prefix.'text_address',
'type' => 'text'
),
...
);
在你的 restaurant_data_form 函数中
function restaurant_data_form()
{
$prefix = 'rest_';
global $post, $rest_custom_meta_fields;
// ...
}
所以它应该看起来像这样(数组在全局范围内)
$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。
【讨论】: