WordPress:Function Reference/get post custom keys

来自站长百科
Xxf3325讨论 | 贡献2008年7月18日 (五) 14:40的版本 (新页面: == Description == Returns an array containing the keys of all custom fields of a particular post or page. See also get_post_custom() and ...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

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()

Usage

%%% <?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

  $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

Note: Regardless of how many values (custom fields) are assigned to one key, that key will only appear once in this array.

Parameters

Related

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