常用函数-get_post_custom_keys()
常用函数-get_post_custom_keys() 说明 返回一个数组,数组中含有特定文章或页面的所有自定…
常用函数-get_post_custom_keys()
说明
返回一个数组,数组中含有特定文章或页面的所有自定义字段的关键字。参见 get_post_custom() 和get_post_custom_values() 。
用法
<?php get_post_custom_keys($post_id); ?>
示例
缺省用法
使用以下示例,创建一个变量($custom_fields_keys)作为含有最近文章所有自定义字段的关键字的数组,并打印。注意:if文本不包括WordPress内部保存的诸如_edit_last and _edit_lock等自定义关键字的值。
<?php
$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
$valuet = trim($value);
if ( '_' == $valuet{0} )
continue;
echo $key . " => " . $value . "<br />";
}
?>
如果文章包含带有mykey和yourkey关键字的自定义字段,输出结果可能会是:
0 => mykey
1 => yourkey
注意:无论一个关键字被赋予多少个值(自定义字段),在数组中它只能显示一次。
参数
$post_id
(整数)(可选)文章编号,将在该文章中检索自定义字段关键字。
默认值:Current post
相关资源
add_post_meta(), delete_post_meta(), update_post_meta(), get_post_meta(), get_post_custom_values(), get_post_custom()
分类:中文手册
类别:WordPress教程、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!