WordPress: Function Reference/get post custom keys:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: == Description == Returns an array containing the keys of all custom fields of a particular post or page. See also get_post_custom() and ...)
 
无编辑摘要
第1行: 第1行:
== Description ==
== Description ==
==描述==


Returns an array containing the keys of all custom fields of a particular post or page. See also [[WordPress:Function_Reference/get_post_custom|get_post_custom()]] and [[WordPress:Function_Reference/get_post_custom_values|get_post_custom_values()]]
Returns an array containing the keys of all custom fields of a particular post or page. See also [[WordPress:Function_Reference/get_post_custom|get_post_custom()]] and [[WordPress:Function_Reference/get_post_custom_values|get_post_custom_values()]]
返回一个数组,包含某篇文章或者网页的所有自定义fields。也看看[[WordPress:Function_Reference/get_post_custom|get_post_custom()]] 和[[WordPress:Function_Reference/get_post_custom_values|get_post_custom_values()]]


== Usage ==
== Usage ==
==用法==
%%% <?php get_post_custom_keys($post_id); ?> %%%


%%% <?php get_post_custom_keys($post_id); ?> %%%
%%% <?php get_post_custom_keys($post_id); ?> %%%
第10行: 第18行:


=== Default Usage ===
=== Default Usage ===
==例子==
===默认用法===
The following example will set a variable (<tt>$custom_field_keys</tt>) as an array containing the keys of all custom fields in the current post, and then print it.
The following example will set a variable (<tt>$custom_field_keys</tt>) as an array containing the keys of all custom fields in the current post, and then print it.
<pre><?php
下面的例子会将一个变数(<tt>$custom_field_keys</tt>)设置为一个数组,包含当前文章的所有自定义fields的关键词,然后再输出。
<pre><?php
<pre><?php


第26行: 第43行:
4 => _wp_page_template<br />
4 => _wp_page_template<br />
</div>
</div>
  $custom_field_keys = get_post_custom_keys();
  foreach ( $custom_field_keys as $key => $value )
    echo $key . " => " . $value . "<br />";
?></pre>
如果文章包含关键字为 ''mykey'' and ''yourkey''的自定义field,输出就会是:
<div style="border:1px solid blue; width:50%; margin: 20px; padding:20px">
0 => mykey<br />
1 => yourkey<br />
2 => _edit_last<br />
3 => _edit_lock<br />
4 => _wp_page_template<br />
</div>
'''''Note:''' Regardless of how many values (custom fields) are assigned to one key, that key will only appear once in this array.''
'''''Note:''' Regardless of how many values (custom fields) are assigned to one key, that key will only appear once in this array.''
'''''注:'''不管一个关键字分配了多少参数值(自定义fields),关键字在数组中只显示一次。''
== Parameters ==


== Parameters ==
==参数==


{{Parameter|$post_id|integer|The post ID whose custom field keys will be retrieved.|optional|Current post}}
{{Parameter|$post_id|integer|The post ID whose custom field keys will be retrieved.|optional|Current post}}
{{Parameter|$post_id|integer|The post ID whose custom field keys will be retrieved.|optional|当前文章t}}


== Related ==
== 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|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]]
[[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|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]]
[[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|get_post_custom()]], [[WordPress:Function Reference/get post custom values|get_post_custom_values()]]

2008年7月19日 (六) 11:19的版本

Description

描述

Returns an array containing the keys of all custom fields of a particular post or page. See also get_post_custom() and get_post_custom_values()

返回一个数组,包含某篇文章或者网页的所有自定义fields。也看看get_post_custom()get_post_custom_values()

Usage

用法

%%% <?php get_post_custom_keys($post_id); ?> %%%

%%% <?php get_post_custom_keys($post_id); ?> %%%

Examples

Default Usage

例子

默认用法

The following example will set a variable ($custom_field_keys) as an array containing the keys of all custom fields in the current post, and then print it.

<?php

下面的例子会将一个变数(<tt>$custom_field_keys</tt>)设置为一个数组,包含当前文章的所有自定义fields的关键词,然后再输出。
<pre><?php

  $custom_field_keys = get_post_custom_keys();
  foreach ( $custom_field_keys as $key => $value )
    echo $key . " => " . $value . "<br />";

?>

If the post contains custom fields with the keys mykey and yourkey, the output would be:

0 => mykey
1 => yourkey
2 => _edit_last
3 => _edit_lock
4 => _wp_page_template




 $custom_field_keys = get_post_custom_keys();
 foreach ( $custom_field_keys as $key => $value )
   echo $key . " => " . $value . "
";

?>

如果文章包含关键字为 mykey and yourkey的自定义field,输出就会是:

0 => mykey
1 => yourkey
2 => _edit_last
3 => _edit_lock
4 => _wp_page_template


Note: Regardless of how many values (custom fields) are assigned to one key, that key will only appear once in this array. 注:不管一个关键字分配了多少参数值(自定义fields),关键字在数组中只显示一次。

Parameters

参数

Related

相关的

add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_values()

add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_values()