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

目录

描述

译文

返回一个多维数组,数组中含有特定文章或页面的所有自定义字段。参见 get_post_custom_keys() and get_post_custom_values() 。

原文

Returns a multidimensional array with all custom fields of a particular post or page. See also get_post_custom_keys() and get_post_custom_values()

get_post_custom() 描述

用法

 <?php get_post_custom($post_id); ?> 

get_post_custom() 用法

参数

$post_id

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

默认值: Current post

get_post_custom() 参数

示例

Default Usage

Use the following example to set a variable ($custom_fields) as a multidimensional array containing all custom fields of the current post.

Retrieving data from the array

The following example will retrieve all custom field values with the key my_custom_field from post ID 72 (assuming there are three custom fields with this key, and the values are "dogs", "47" and "This is another value").

0 => dogs
1 => 47
2 => This is another value

Note: not only does the function return a multi-dimensional array (ie: always be prepared to deal with an array of arrays, even if expecting array of single values), but it also returns serialized values of any arrays stored as meta values.
If you expect that possibly an array may be stored as a metavalue, then be prepared to maybe_unserialize.

get_post_custom() 示例

相关