post_custom

Retrieve post custom meta data field.

Description

(false|string|array) post_custom( (string) $key = '' ); 

Returns (false|string|array)

Array of values or single value, if only one element exists. False will be returned if key does not exist.

Parameters (1)

0. $key — Optional. (string) => ''
Meta data key name.

Usage

  1. if ( !function_exists( 'post_custom' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // Meta data key name. 
  5. $key = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = post_custom($key); 
  9.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function post_custom( $key = '' ) { 
  2. $custom = get_post_custom(); 
  3.  
  4. if ( !isset( $custom[$key] ) ) 
  5. return false; 
  6. elseif ( 1 == count($custom[$key]) ) 
  7. return $custom[$key][0]; 
  8. else 
  9. return $custom[$key];