WordPress:Function Reference/get post custom
Description
描述
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() 返回一个多维数组,带有某篇文章的或者网页的所有自定义fields。也看看get_post_custom_keys() 和get_post_custom_values()
Usage
用法
%%% <?php get_post_custom($post_id); ?> %%%
%%% <?php get_post_custom($post_id); ?> %%%
Examples
Default Usage
例子
默认用法
Use the following example to set a variable ($custom_fields) as a multidimensional array containing all custom fields of the current post.
<?php $custom_fields = get_post_custom(); ?>
使用下面的例子,设置一个变数($custom_fields)作为多维数组,包含当前文章所有的自定义field。 <?php $custom_fields = get_post_custom(); ?>
Retrieving data from the array
得到数组中的数据
The following example will retrieve all custom field values with the key my_custom_field from the post with the ID 72 (assuming there are three custom fields with this key, and the values are "dogs", "47" and "This is another value").
下面的例子会返回ID是72的文章,关键字为my_custom_field的所有自定义field参数值(既然这个关键词拥有三个自定义field,参数值分别是"狗""47"和 "这是另一个参数值")。
<?php $custom_fields = get_post_custom(); $my_custom_field = $custom_fields['my_custom_field']; foreach ( $my_custom_field as $key => $value ) echo $key . " => " . $value . "<br />"; ?>
0 => dogs
1 => 47
2 => This is another value
<?php $custom_fields = get_post_custom(); $my_custom_field = $custom_fields['my_custom_field']; foreach ( $my_custom_field as $key => $value ) echo $key . " => " . $value . "<br />"; ?>
0 =>狗
1 => 47
2 => 这是另一个参数值
Parameters
参数
Related
相关的
add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom_values(), get_post_custom_keys()
add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom_values(), get_post_custom_keys()