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

WordPress:Function Reference/add post meta

來自站長百科
Xxf3325討論 | 貢獻2008年7月18日 (五) 10:34的版本 (新頁面: ==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>...)
(差異) ←上一版本 | 最后版本 (差異) | 下一版本→ (差異)
跳轉(zhuǎn)至: 導(dǎo)航、? 搜索

Description

add_post_meta adds a custom (meta) field to the specified post.

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.

Usage

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

Examples

Default Usage

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

Adding or updating a unique field

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

 <?php add_post_meta(7, 'fruit', 'banana', true) or 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:

<?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.

Making a "Hidden" Custom Field

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.

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.

Parameters

Related

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