get_post_meta

Retrieve post meta field for a post.

Description

get_post_meta( (int) $post_id, (string) $key = '', (bool) $single = false ); 

Parameters (3)

0. $post_id (int)
The post id.
1. $key — Optional. (string) => ''
The meta key to retrieve. By default, returns data for all keys. Default empty.
2. $single — Optional. (bool) => false
Whether to return a single value. Default false.

Usage

  1. if ( !function_exists( 'get_post_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // Optional. The meta key to retrieve. By default, returns 
  8. // data for all keys. Default empty. 
  9. $key = ''; 
  10.  
  11. // Optional. Whether to return a single value. Default false. 
  12. $single = false; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = get_post_meta($post_id, $key, $single); 
  16.  

Defined (1)

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

/wp-includes/post.php  
  1. function get_post_meta( $post_id, $key = '', $single = false ) { 
  2. return get_metadata('post', $post_id, $key, $single);