Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post custom keys


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


 <?php get_post_custom_keys($post_id); ?> 


(integer) (optional) The post ID whose custom field keys will be retrieved.
Default: Current post


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. Note: the if test excludes values for WordPress internally maintained custom keys such as _edit_last and _edit_lock.


$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
    $valuet = trim($value);
    if ( '_' == $valuet{0} )
    echo $key . " => " . $value . "<br />";

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

0 => mykey
1 => yourkey

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

Source File

get_post_custom_keys() is located in wp-includes/post.php.


Custom Fields: the_meta(), get_post_meta(), add_post_meta(), update_post_meta(), delete_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys() (See Also: post_meta Function Examples)

See also index of Function Reference and index of Template Tags.