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

WordPress:Function Reference/add post meta

來自站長百科
Fludlen討論 | 貢獻2008年7月19日 (六) 10:39的版本
跳轉(zhuǎn)至: 導航、? 搜索

Description

描述

add_post_meta adds a custom (meta) field to the specified post. add_post_meta為某篇文章添加了一個自定義的(meta)區(qū)。


If the $unique parameter is set to true and the specified meta key already exists, the function returns false and makes no changes; otherwise, it returns true.

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

Usage

用法

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

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

Examples

例子

Default Usage

默認用法

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

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

Adding or updating a unique field

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

Adds a new field if the key doesn't exist, or updates the existing field.

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

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

Other Examples

其它的例子

If you wanted to make sure that there were no fields with the key "my_key", before adding it:

如果你想要確定沒有帶有關(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.'); ?>
...


<?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.'); ?>
...


For a more detailed example, go to the post_meta Functions Examples page.

更詳細的例子,請進入post_meta 函數(shù)例子網(wǎng)頁。

Making a "Hidden" Custom Field

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

If you are a plugin / theme developer and you are planning to use custom fields to store parameters related to your plugin or template, it is interesting to note that WordPress wont show keys starting with an "_" (underscore) in the custom fields list at the page / post editing page. That being said, it is a good practice to use an underscore as the first character in your custom parameters, that way your settings are stored as custom fields, but they won't display in the custom fields list in the admin UI.

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

The following example:

下面的例子:

<?php add_post_meta(68, '_color', 'red', true); ?>

will add a unique custom field with the key name "_color" and the value "red" but this custom field will not display in the page / post editing page.

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

Parameters

參數(shù)

Related

相關(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()