2013-04-30 109 views

回答

0

其实你已经宣布你$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

+0

It works !!! Thanks !!! – aquanat 2013-05-15 12:27:46

相关问题