get_post_custom_values()通过id获取文章/页面所有的自定义字段(post meta)的值

目录

描述

译文

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

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

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

参见get_post_custom_keys() and get_post_custom_values() 。

原文

This function is useful if you wish to access a custom field that is not unique, i.e. has more than 1 value associated with it. Otherwise, you might wish to look at get_post_meta().

Returns an array containing all the values of the custom fields with a particular key ($key) of a post with ID $post_id (defaults to the current post if unspecified).

Returns nothing if no such key exists, or none is entered.

See also get_post_custom() and get_post_custom_keys().

get_post_custom_values() 描述

用法

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

get_post_custom_values() 用法

参数

$key

(string) (必填) The key whose values you want returned.

默认值: None

$post_id

(integer) (可选) The post ID whose custom fields will be retrieved.

默认值: Current post

get_post_custom_values() 参数

示例

Default Usage

Let's assume the current post has 3 values associated with the (custom) field my_key.

You could show them through:

get_post_custom_values() 示例

源文件

get_post_custom_values() 函数的代码位于 wp-includes/post.php.

get_post_custom_values() 源文件

相关