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

WordPress: Function Reference/add post meta:修訂間差異

來自站長百科
跳轉(zhuǎn)至: 導(dǎo)航、? 搜索
無編輯摘要
無編輯摘要
第1行: 第1行:
==Description==
==描述==
==描述==
[[WordPress:Function Reference/add post meta|add_post_meta]] adds a custom (meta) field to the specified post.
[[WordPress:Function Reference/add post meta|add_post_meta]]為某篇文章添加了一個自定義的(meta)區(qū)。
[[WordPress:Function Reference/add post meta|add_post_meta]]為某篇文章添加了一個自定義的(meta)區(qū)。
If the <tt>$unique</tt> parameter is set to <var>true</var> and the specified meta key already exists, the function returns <var>false</var> and makes no changes; otherwise, it returns <var>true</var>.


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


==Usage==
==用法==
==用法==
%%% <?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?> %%%


%%% <?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===


===默認(rèn)用法===
===默認(rèn)用法===
<?php add_post_meta($68, 'my_key', 47); ?>


<?php add_post_meta($68, 'my_key', 47); ?>
<?php add_post_meta($68, 'my_key', 47); ?>
===Adding or updating a unique field===


===添加或者更新一個獨特的區(qū)===
===添加或者更新一個獨特的區(qū)===
Adds a new field if the key doesn't exist, or updates the existing field.


如果你存在關(guān)鍵詞,添加一個新的field,或者更新現(xiàn)存的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'); ?>
?? <?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,添加之前:
如果你想要確定沒有帶有關(guān)鍵字''"my_key"''的fieled,添加之前:
<?php add_post_meta(68, 'my_key', '47', true); ?>
To add several values to the key ''"my_key"'':
<pre><?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.'); ?>
...</pre>


<?php add_post_meta(68, 'my_key', '47', true); ?>
<?php add_post_meta(68, 'my_key', '47', true); ?>
第58行: 第30行:
<?php add_post_meta(68, 'my_key', 'The quick, brown fox jumped over the lazy dog.'); ?>
<?php add_post_meta(68, 'my_key', 'The quick, brown fox jumped over the lazy dog.'); ?>
...</pre>
...</pre>
For a more detailed example, go to the [[WordPress:Function Reference/post meta Function Examples|post_meta Functions Examples]] page.


更詳細(xì)的例子,請進(jìn)入[[WordPress:Function Reference/post meta Function Examples|post_meta 函數(shù)例子]]網(wǎng)頁。
更詳細(xì)的例子,請進(jìn)入[[WordPress:Function Reference/post meta Function Examples|post_meta 函數(shù)例子]]網(wǎng)頁。
=== Making a "Hidden" Custom Field ===


=== 制作一個 "隱藏的" 自定義區(qū) ===
=== 制作一個 "隱藏的" 自定義區(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習(xí)慣于顯示網(wǎng)頁/文章編輯網(wǎng)頁中自定義field列表上以"_"(下劃線)開始的關(guān)鍵字。就是說,在自定義參數(shù)中將下劃線設(shè)置為第一個字符,是個很好的做法,這樣你可以將設(shè)置儲存為自定義fields,但是你的設(shè)置不會在管理UI中的自定義fields列表中顯示。
如果你是一個插件/主題開發(fā)人員而且你計劃使用自定義field儲存與你的插件或者主題相關(guān)的參數(shù),你或饒有興趣地發(fā)現(xiàn),WordPress習(xí)慣于顯示網(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); ?>
<?php add_post_meta(68, '_color', 'red', true); ?>
會添加一個關(guān)鍵字是 "_color" 的自定義范圍而且這個自定義范圍中的參數(shù)值"red"不會在網(wǎng)頁/文章編輯網(wǎng)頁中顯示。
會添加一個關(guān)鍵字是 "_color" 的自定義范圍而且這個自定義范圍中的參數(shù)值"red"不會在網(wǎng)頁/文章編輯網(wǎng)頁中顯示。
==Parameters==


==參數(shù)==
==參數(shù)==
第99行: 第57行:
{{Parameter|$unique|boolean|你是否想要獨特的關(guān)鍵字。如果設(shè)置為真的,能夠確保不存在文章的關(guān)鍵字with <tt>$meta_key</tt> 如果這個field已經(jīng)存在,這個關(guān)鍵詞就不會得到添加。|optional|false}}
{{Parameter|$unique|boolean|你是否想要獨特的關(guān)鍵字。如果設(shè)置為真的,能夠確保不存在文章的關(guān)鍵字with <tt>$meta_key</tt> 如果這個field已經(jīng)存在,這個關(guān)鍵詞就不會得到添加。|optional|false}}


==Related==
==相關(guān)的==
==相關(guān)的==



2008年7月22日 (二) 18:12的版本

描述

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

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

用法

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

例子

默認(rèn)用法

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

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

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

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

其它的例子

如果你想要確定沒有帶有關(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ì)的例子,請進(jìn)入post_meta 函數(shù)例子網(wǎng)頁。

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

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

下面的例子:

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

參數(shù)

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