Title: get_post_custom_keys
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_post_custom_keys( int $post_id ): array|void

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#wp--skip-link--target)

Retrieves meta field names for a post.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#description)󠁿

If there are no meta fields, then nothing (null) will be returned.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#parameters)󠁿

 `$post_id`intoptional

Post ID. Default is the ID of the global `$post`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#return)󠁿

 array|void Array of the keys, if retrieved.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#source)󠁿

    ```php
    function get_post_custom_keys( $post_id = 0 ) {
    	$custom = get_post_custom( $post_id );

    	if ( ! is_array( $custom ) ) {
    		return;
    	}

    	$keys = array_keys( $custom );
    	if ( $keys ) {
    		return $keys;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/post.php#L2825)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/post.php#L2825-L2836)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#related)󠁿

| Uses | Description | 
| [get_post_custom()](https://developer.wordpress.org/reference/functions/get_post_custom/)`wp-includes/post.php` |

Retrieves post meta fields, based on post ID.

  |

| Used by | Description | 
| [the_meta()](https://developer.wordpress.org/reference/functions/the_meta/)`wp-includes/post-template.php` |

Displays a list of post custom fields.

  | 
| [WP_Embed::delete_oembed_caches()](https://developer.wordpress.org/reference/classes/wp_embed/delete_oembed_caches/)`wp-includes/class-wp-embed.php` |

Deletes all oEmbed caches. Unused by core as of 4.0.0.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.2.0](https://developer.wordpress.org/reference/since/1.2.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_post_custom_keys/?output_format=md#comment-content-664)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_post_custom_keys/#comment-664)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_custom_keys%2F%23comment-664)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_custom_keys%2F%23comment-664)
 4.  **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`.
 5.      ```php
         <?php
     
         $custom_field_keys = get_post_custom_keys();
         foreach ( $custom_field_keys as $key => $value ) {
             $valuet = trim($value);
             if ( '_' == $valuet{0} )
                 continue;
             echo $key . " => " . $value . "<br />";
         }
         ?>
         ```
     
 6.  If the post contains custom fields with the keys `mykey` and `yourkey`, the output
     would be something like:
 7.      ```php
         0 => mykey
         1 => yourkey
         ```
     
 8.  _Note: Regardless of how many values (custom fields) are assigned to one key, 
     that key will only appear once in this array._
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_custom_keys%2F%3Freplytocom%3D664%23feedback-editor-664)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_custom_keys%2F)
before being able to contribute a note or feedback.