WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計(jì)算
- 微博營(yíng)銷
- 虛擬主機(jī)管理系統(tǒng)
- 開放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
WordPress: Function Reference/add post meta:修訂間差異
(新頁面: ==Description== add_post_meta adds a custom (meta) field to the specified post. If the <tt>$unique</tt> parameter is set to <var>true</var>...) ? |
? |
||
(未顯示2個(gè)用戶的4個(gè)中間版本) | |||
第1行: | 第1行: | ||
== | ==描述== | ||
[[WordPress:Function Reference/add post meta|add_post_meta]] | [[WordPress:Function Reference/add post meta|add_post_meta]]為某篇文章添加了一個(gè)自定義的(meta)區(qū)。 | ||
如果<tt>$unique</tt>參數(shù)設(shè)置為<var>true</var>而且已經(jīng)存在特別的meta關(guān)鍵詞,函數(shù)返回<var>false</var>而且不做什么更改;否則的話,函數(shù)返回<var>true</var>。 | |||
? | |||
==用法== | |||
%%% <?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?> %%% | %%% <?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'); ?> | |||
? | |||
===其它的例子=== | |||
? | |||
如果你想要確定沒有帶有關(guān)鍵字''"my_key"''的fieled,添加之前: | |||
? | |||
<?php add_post_meta(68, 'my_key', '47', true); ?> | |||
To add several values to the key ''"my_key"'': | To add several values to the key ''"my_key"'': | ||
<pre><?php add_post_meta(68, 'my_key', '47'); ?> | <pre><?php add_post_meta(68, 'my_key', '47'); ?> | ||
第24行: | 第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> | ||
=== | 更詳細(xì)的例子,請(qǐng)進(jìn)入[[WordPress:Function Reference/post meta Function Examples|post_meta 函數(shù)例子]]網(wǎng)頁。 | ||
? | |||
=== 制作一個(gè) "隱藏的" 自定義區(qū) === | |||
? | |||
如果你是一個(gè)插件/主題開發(fā)人員而且你計(jì)劃使用自定義field儲(chǔ)存與你的插件或者主題相關(guān)的參數(shù),你會(huì)饒有興趣地發(fā)現(xiàn),WordPress習(xí)慣于顯示網(wǎng)頁/文章編輯網(wǎng)頁中自定義field列表上以"_"(下劃線)開始的關(guān)鍵字。就是說,在自定義參數(shù)中將下劃線設(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)頁/文章編輯網(wǎng)頁中顯示。 | |||
? | |||
==參數(shù)== | |||
{{Parameter|$post_id|integer|The ID of the post to which you will add a custom field.}} | {{Parameter|$post_id|integer|The ID of the post to which you will add a custom field.}} | ||
{{Parameter|$meta_key|string|The key of the custom field you will add.}} | {{Parameter|$meta_key|string|The key of the custom field you will add.}} | ||
{{Parameter|$meta_value|string|The value of the custom field you will add.}} | {{Parameter|$meta_value|string|The value of the custom field you will add.}} | ||
{{Parameter|$unique|boolean|Whether or not you want the key to be unique. When set to true, this will ensure that there is not already a custom field attached to the post with <tt>$meta_key</tt> as it's key, and, if such a field already exists, the key will not be added.|optional|false}} | {{Parameter|$unique|boolean|Whether or not you want the key to be unique. When set to true, this will ensure that there is not already a custom field attached to the post with <tt>$meta_key</tt> as it's key, and, if such a field already exists, the key will not be added.|optional|false}} | ||
== | ? | ||
? | |||
{{Parameter|$post_id|integer|你添加一個(gè)自定義范圍的文章的ID。}} | |||
{{Parameter|$meta_key|string|你將要添加的自定義field的關(guān)鍵詞。}} | |||
{{Parameter|$meta_value|string|你將要添加的自定義field的參數(shù)值。}} | |||
? | |||
? | |||
{{Parameter|$unique|boolean|你是否想要獨(dú)特的關(guān)鍵字。如果設(shè)置為真的,能夠確保不存在文章的關(guān)鍵字with <tt>$meta_key</tt> 如果這個(gè)field已經(jīng)存在,這個(gè)關(guān)鍵詞就不會(huì)得到添加。|optional|false}} | |||
? | |||
==相關(guān)的== | |||
? | |||
[[WordPress:Function Reference/delete post meta|delete_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post custom|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]] | |||
? | |||
[[WordPress:Function Reference/delete post meta|delete_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post custom|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]] | [[WordPress:Function Reference/delete post meta|delete_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post custom|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]] |
2008年9月24日 (三) 11:28的最新版本
描述[ ]
add_post_meta為某篇文章添加了一個(gè)自定義的(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); ?>
添加或者更新一個(gè)獨(dú)特的區(qū)[ ]
如果你存在關(guān)鍵詞,添加一個(gè)新的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ì)的例子,請(qǐng)進(jìn)入post_meta 函數(shù)例子網(wǎng)頁。
制作一個(gè) "隱藏的" 自定義區(qū)[ ]
如果你是一個(gè)插件/主題開發(fā)人員而且你計(jì)劃使用自定義field儲(chǔ)存與你的插件或者主題相關(guān)的參數(shù),你會(huì)饒有興趣地發(fā)現(xiàn),WordPress習(xí)慣于顯示網(wǎng)頁/文章編輯網(wǎng)頁中自定義field列表上以"_"(下劃線)開始的關(guān)鍵字。就是說,在自定義參數(shù)中將下劃線設(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)頁/文章編輯網(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()