get_post_custom_values

Retrieve values for a custom post field.

Description

(array|null) get_post_custom_values( (string) $key = '', (int) $post_id = 0 ); 

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

Returns (array|null)

Meta field values.

Parameters (2)

0. $key — Optional. (string) => ''
Meta field key. Default empty.
1. $post_id — Optional. (int)
Post ID. Default is ID of the global $post.

Usage

  1. if ( !function_exists( 'get_post_custom_values' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Meta field key. Default empty. 
  5. $key = ''; 
  6.  
  7. // Optional. Post ID. Default is ID of the global $post. 
  8. $post_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_post_custom_values($key, $post_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function get_post_custom_values( $key = '', $post_id = 0 ) { 
  2. if ( !$key ) 
  3. return null; 
  4.  
  5. $custom = get_post_custom($post_id); 
  6.  
  7. return isset($custom[$key]) ? $custom[$key] : null;