WordPress常用函数get post custom keys

来自站长百科
跳转至: 导航、​ 搜索

导航: 上一页 | 首页 | WordPress中文论坛 | WordPress主机 | CMS程序 | 论坛程序 | ECShop | ShopNC | PowerEasy

常用函数-get_post_custom_keys()

说明[ ]

返回一个数组,数组中含有特定文章或页面的所有自定义字段的关键字get_post_custom_keys() and 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 . "
"; } ?>

如果文章包含带有mykey和yourkey关键字的自定义字段,输出结果可能会是:

0 => mykey
1 => yourkey

注意:无论一个关键字被赋予多少个值(自定义字段),在数组中它只能显示一次。

参数

$post_id

(整数)(可选)文章编号,将在该文章中检索自定义字段关键字。

默认值:Current post

相关资源 add_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys()


相关条目[ ]