2012-03-02 47 views
0

我做了這些樹教程來創建自定義元框。Wordpress元框 - WP tuts教程

http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/ http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-2-advanced-fields/ http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-3-extra-fields/

,但我不知道該怎麼稱呼從單個值領域。我用這個php腳本 $ meta = get_post_meta($ post-> ID,$ field ['custom_text'],true); echo $ meta;

但id不起作用。有人知道我做錯了什麼嗎?

回答

0

好吧,很難說如果沒有看到你是如何實現你的定製元框 - 這可能是一個問題 - 但同時,檢查WordPress的codex,以確保你正確使用get_post_meta()函數。第二個參數應該是一個字符串,代表您正在檢索的元字段的關鍵字(名稱)。

從食品:

$meta_values = get_post_meta($post_id, $key, $single); 

// where $key = A string containing the name of the meta value you want. 

所以仔細檢查你傳遞的($場[「custom_text」])確實值實際上包含佔元字段的名稱的字符串你正在嘗試檢索。

0

正如之前的海報所述,您正在使用get_post_meta錯誤。假設你創建了一個名爲「custom_field」您的自定義元盒子裏的自定義字段,你會得到表示字段的值與此代碼:

$field_value = get_post_meta($post_id, 'custom_field', true); 
echo $field_value; // outputs the field value. 

如果這不起作用你要麼得到的名稱字段錯誤,或者當你添加你的metabox時你做錯了,如果是這種情況,請檢查你的php錯誤日誌中是否有錯誤。