首页    >    中文手册    >   常用函数-get_post_custom_values()

常用函数-get_post_custom_values()

常用函数-get_post_custom_values()

说明

该函数可用于获取非独有的自定义字段,比如含有至少两个值的字段。其他情况下可以使用 get_post_meta()

返回一个数组,数组中包含带有文章指定关键字的自定义字段的所有值,文章编号为$post_id(未指定编号时默认为最新文章)。

关键字不存在时不返回值,或返回空值。

参见 get_post_custom()get_post_custom_keys()

用法

<?php get_post_custom_values($key, $post_id); ?>

示例

缺省用法

假设最新文章有三个与my_key(自定义)字段相关联的值。

从下面的代码中可以看到:

<?php      

  $mykey_values = get_post_custom_values('my_key');    
  foreach ( $mykey_values as $key => $value ) {      
    echo "$key  => $value ('my_key')<br />";     
  }    

?>


0 => First value ('my_key')  
1 => Second value ('my_key')  
2 => Third value ('my_key')  

参数

$key

(字符)(必需)希望返回值的关键字

默认值:None

$post_id

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

默认值:Current post

相关资源

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

 

分类:中文手册

* 版权声明:作者WordPress啦! 转载请注明出处。