get_post_custom

Retrieve post meta fields, based on post ID.

Description

(array) get_post_custom( (int) $post_id = 0 ); 

The post meta fields are retrieved from the cache where possible, so the function is optimized to be called more than once.

Returns (array)

Post meta for the given post.

Parameters (1)

0. $post_id — Optional. (int)
Post ID. Default is ID of the global $post.

Usage

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

Defined (1)

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

/wp-includes/post.php  
  1. function get_post_custom( $post_id = 0 ) { 
  2. $post_id = absint( $post_id ); 
  3. if ( ! $post_id ) 
  4. $post_id = get_the_ID(); 
  5.  
  6. return get_post_meta( $post_id );