WordPress: Function Reference/get post custom:修订间差异
来自站长百科
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
==描述== | ==描述== | ||
返回一个多维数组,带有某篇文章的或者网页的所有自定义fields。也看看[[WordPress:Function_Reference/get_post_custom_keys|get_post_custom_keys()]] 和[[WordPress:Function_Reference/get_post_custom_values|get_post_custom_values()]] | 返回一个多维数组,带有某篇文章的或者网页的所有自定义fields。也看看[[WordPress:Function_Reference/get_post_custom_keys|get_post_custom_keys()]] 和[[WordPress:Function_Reference/get_post_custom_values|get_post_custom_values()]] | ||
==用法== | ==用法== | ||
%%% <?php get_post_custom($post_id); ?> %%% | %%% <?php get_post_custom($post_id); ?> %%% | ||
==例子== | ==例子== | ||
===默认用法=== | ===默认用法=== | ||
使用下面的例子,设置一个变数(<tt>$custom_fields</tt>)作为多维数组,包含当前文章所有的自定义field。 | 使用下面的例子,设置一个变数(<tt>$custom_fields</tt>)作为多维数组,包含当前文章所有的自定义field。 | ||
<?php $custom_fields = get_post_custom(); ?> | <?php $custom_fields = get_post_custom(); ?> | ||
=== | === 检索数组中的数据 === | ||
下面的例子会检索ID是''72''的文章,关键字为''my_custom_field''的所有自定义field参数值(既然这个关键词拥有三个自定义field,参数值分别是"狗""47"和 "这是另一个参数值")。 | |||
<pre><?php | <pre><?php | ||
第49行: | 第32行: | ||
2 => This is another value | 2 => This is another value | ||
</div> | </div> | ||
==参数== | ==参数== | ||
{{Parameter|$post_id|integer|The post ID whose custom fields will be retrieved.|optional|当前文章}} | {{Parameter|$post_id|integer|The post ID whose custom fields will be retrieved.|optional|当前文章}} | ||
==相关的== | ==相关的== | ||
[[WordPress:Function Reference/add post meta|add_post_meta()]], [[WordPress:Function Reference/delete post meta|delete_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]] | [[WordPress:Function Reference/add post meta|add_post_meta()]], [[WordPress:Function Reference/delete post meta|delete_post_meta()]], [[WordPress:Function Reference/get post meta|get_post_meta()]], [[WordPress:Function Reference/update post meta|update_post_meta()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]], [[WordPress:Function Reference/get post custom keys|get_post_custom_keys()]] |
2008年7月23日 (三) 14:02的最新版本
描述[ ]
返回一个多维数组,带有某篇文章的或者网页的所有自定义fields。也看看get_post_custom_keys() 和get_post_custom_values()
用法[ ]
%%% <?php get_post_custom($post_id); ?> %%%
例子[ ]
默认用法[ ]
使用下面的例子,设置一个变数($custom_fields)作为多维数组,包含当前文章所有的自定义field。 <?php $custom_fields = get_post_custom(); ?>
检索数组中的数据[ ]
下面的例子会检索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
参数[ ]
相关的[ ]
add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom_values(), get_post_custom_keys()