Title: get_post_custom_values
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_post_custom_values( string $key, int $post_id ): array|null

## In this article

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

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

Retrieves values for a custom post field.

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

The parameters must not be considered optional. All of the post meta fields will
be retrieved and only the meta field key values returned.

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

 `$key`stringoptional

Meta field key. Default empty.

`$post_id`intoptional

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

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

 array|null Meta field values.

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

    ```php
    function get_post_custom_values( $key = '', $post_id = 0 ) {
    	if ( ! $key ) {
    		return null;
    	}

    	$custom = get_post_custom( $post_id );

    	return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
    }
    ```

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

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_custom_values/?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.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_custom_values/?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_values/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_post_custom_values/?output_format=md#comment-content-701)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_post_custom_values/#comment-701)
 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_values%2F%23comment-701)
     Vote results for this note: 1[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_values%2F%23comment-701)
 4.  **Default usage example.**
 5.  Let’s assume the current post has 3 values associated with the (custom) field 
     my_key.
 6.  You could show them through:
 7.      ```php
         $mykey_values = get_post_custom_values( 'my_key' );
     
         foreach ( $mykey_values as $key => $value ) {
         	echo "$key => $value ( 'my_key' )<br />"; 
         }
         ```
     
 8.  The above example will output:
 9.      ```php
         0 => First value ( 'my_key' )
         1 => Second value ( 'my_key' )
         2 => Third value ( 'my_key' )
         ```
     
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_custom_values%2F%3Freplytocom%3D701%23feedback-editor-701)

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