WordPress常用函数get post meta:修订间差异
来自站长百科
(新页面: <span style="border:1px solid #000; text-align:center; float:right; padding:6px;"><strong>导航:</strong> 上一页 | {{Template:WordPress导航}}</span> ...) |
(→示例) |
||
第14行: | 第14行: | ||
'''其他示例''' | '''其他示例''' | ||
仅检索给定关键字的第一个值: | 仅检索给定关键字的第一个值: | ||
<?php $key_1_value = get_post_meta(76, 'key_1', true); ?> | <?php $key_1_value = get_post_meta(76, 'key_1', true); ?> | ||
第47行: | 第48行: | ||
[http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-add_post_meta%28%29.html add_post_meta()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_meta%28%29.html get_post_meta()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-update_post_meta%28%29.html update_post_meta()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_custom%28%29.html get_post_custom()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_custom_values%28%29.html get_post_custom_values()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_custom_keys%28%29.html get_post_custom_keys()] | [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-add_post_meta%28%29.html add_post_meta()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_meta%28%29.html get_post_meta()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-update_post_meta%28%29.html update_post_meta()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_custom%28%29.html get_post_custom()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_custom_values%28%29.html get_post_custom_values()], [http://www.wordpress.la/codex-%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0-get_post_custom_keys%28%29.html get_post_custom_keys()] | ||
==相关条目== | ==相关条目== | ||
*[[Drupal]] | *[[Drupal]] |
2010年5月24日 (一) 17:43的最新版本
导航: 上一页 | 首页 | WordPress中文论坛 | WordPress主机 | CMS程序 | 论坛程序 | ECShop | ShopNC | PowerEasy
说明[ ]
该函数返回指定文章中含有指定关键字自定义字段的值。参见update_post_meta(), get_post_meta() 和add_post_meta()。
用法[ ]
<?php $meta_values = get_post_meta($post_id, $key, $single); ?>
示例[ ]
缺省用法
<?php $key_1_values = get_post_meta(76, 'key_1'); ?>
其他示例
仅检索给定关键字的第一个值:
<?php $key_1_value = get_post_meta(76, 'key_1', true); ?>
更详细的示例参见 post_meta函数示例页面。
参数
$post_id
(整数)(必需)希望从中得到数据的文章的编号。用$post->ID获取文章编号。
默认值:None
$key
(字符)(必需)字符,字符中含有希望的meta值的名称。
默认值:None
$single
(布尔值)(可选)如果默认值设为true,函数返回单个字符形式的结果。如果为false或为设置,则函数返回自定义字段的数组。
默认值:false
返回的值
- 若$single设为false或空,函数返回一个包含指定关键字的所有值的数组
- 若$single设为true,函数返回指定关键字的第一个值(不是数组)
无论$single值是什么,如果没有指定关键字,函数将返回空的字符。
相关资源
add_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys()