久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔

WordPress:Function Reference/add post meta

來(lái)自站長(zhǎng)百科
Xxf3325討論 | 貢獻(xiàn)2008年7月22日 (二) 18:13的版本 →?參數(shù)
跳轉(zhuǎn)至: 導(dǎo)航、? 搜索

描述

add_post_meta為某篇文章添加了一個(gè)自定義的(meta)區(qū)。

如果$unique參數(shù)設(shè)置為true而且已經(jīng)存在特別的meta關(guān)鍵詞,函數(shù)返回false而且不做什么更改;否則的話(huà),函數(shù)返回true。

用法

%%% <?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?> %%%

例子

默認(rèn)用法

<?php add_post_meta($68, 'my_key', 47); ?>

添加或者更新一個(gè)獨(dú)特的區(qū)

如果你存在關(guān)鍵詞,添加一個(gè)新的field,或者更新現(xiàn)存的field。

 <?php add_post_meta(7, 'fruit', 'banana', true) 或者update_post_meta(7, 'fruit', 'banana'); ?>

其它的例子

如果你想要確定沒(méi)有帶有關(guān)鍵字"my_key"的fieled,添加之前:

<?php add_post_meta(68, 'my_key', '47', true); ?> To add several values to the key "my_key":

<?php add_post_meta(68, 'my_key', '47'); ?>
<?php add_post_meta(68, 'my_key', '682'); ?>
<?php add_post_meta(68, 'my_key', 'The quick, brown fox jumped over the lazy dog.'); ?>
...

更詳細(xì)的例子,請(qǐng)進(jìn)入post_meta 函數(shù)例子網(wǎng)頁(yè)。

制作一個(gè) "隱藏的" 自定義區(qū)

如果你是一個(gè)插件/主題開(kāi)發(fā)人員而且你計(jì)劃使用自定義field儲(chǔ)存與你的插件或者主題相關(guān)的參數(shù),你或饒有興趣地發(fā)現(xiàn),WordPress習(xí)慣于顯示網(wǎng)頁(yè)/文章編輯網(wǎng)頁(yè)中自定義field列表上以"_"(下劃線(xiàn))開(kāi)始的關(guān)鍵字。就是說(shuō),在自定義參數(shù)中將下劃線(xiàn)設(shè)置為第一個(gè)字符,是個(gè)很好的做法,這樣你可以將設(shè)置儲(chǔ)存為自定義fields,但是你的設(shè)置不會(huì)在管理UI中的自定義fields列表中顯示。

下面的例子:

<?php add_post_meta(68, '_color', 'red', true); ?> 會(huì)添加一個(gè)關(guān)鍵字是 "_color" 的自定義范圍而且這個(gè)自定義范圍中的參數(shù)值"red"不會(huì)在網(wǎng)頁(yè)/文章編輯網(wǎng)頁(yè)中顯示。

參數(shù)

$post_id|integer|The ID of the post to which you will add a custom field.







相關(guān)的

delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys()

delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys()