2013-04-30 99 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

相關問題