编辑“WordPress:Function Reference/get post custom

跳转至: 导航、​ 搜索
警告:您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您登录创建一个账户,您的编辑将归属于您的用户名,且将享受其他好处。

该编辑可以被撤销。 请检查下面的对比以核实您想要撤销的内容,然后发布下面的更改以完成撤销。

最后版本 您的文本
第1行: 第1行:
== Description ==
==描述==
==描述==


Returns a multidimensional array with all custom fields of a particular post or page. See also [[WordPress:Function_Reference/get_post_custom_keys|get_post_custom_keys()]] and [[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()]]
返回一个多维数组,带有某篇文章的或者网页的所有自定义fields。也看看[[WordPress:Function_Reference/get_post_custom_keys|get_post_custom_keys()]] 和[[WordPress:Function_Reference/get_post_custom_values|get_post_custom_values()]]
== Usage ==


==用法==
==用法==


%%% <?php get_post_custom($post_id); ?> %%%
%%% <?php get_post_custom($post_id); ?> %%%
%%% <?php get_post_custom($post_id); ?> %%%
== Examples ==
=== Default Usage ===


==例子==
==例子==
===默认用法===
===默认用法===
Use the following example to set a variable (<tt>$custom_fields</tt>) as a multidimensional array containing all custom fields of the current post.
<?php $custom_fields = get_post_custom(); ?>


使用下面的例子,设置一个变数(<tt>$custom_fields</tt>)作为多维数组,包含当前文章所有的自定义field。
使用下面的例子,设置一个变数(<tt>$custom_fields</tt>)作为多维数组,包含当前文章所有的自定义field。
<?php $custom_fields = get_post_custom(); ?>
<?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"和 "这是另一个参数值")。
下面的例子会返回ID是''72''的文章,关键字为''my_custom_field''的所有自定义field参数值(既然这个关键词拥有三个自定义field,参数值分别是"狗""47"和 "这是另一个参数值")。


<pre><?php
<pre><?php
第32行: 第49行:
2 => This is another value
2 => This is another value
</div>
</div>
<pre><?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 />";
?>
</pre>
<div style="border:1px solid blue; width:50%; margin: 20px; padding:20px">
0 =>狗<br/>
1 => 47<br/>
2 => 这是另一个参数值
</div>
== Parameters ==


==参数==
==参数==


{{Parameter|$post_id|integer|The post ID whose custom fields will be retrieved.|optional|Current post}}


{{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|当前文章}}
== Related ==


==相关的==
==相关的==
[[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()]]
[[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-mediawiki:版权的细节)。 未经许可,请勿提交受版权保护的作品!
取消 编辑帮助(在新窗口中打开)

本页使用的模板: