get_post_custom_keys

Retrieve meta field names for a post.

Description

(array|void) get_post_custom_keys( (int) $post_id = 0 ); 

If there are no meta fields, then nothing (null) will be returned.

Returns (array|void)

Array of the keys, if retrieved.

Parameters (1)

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

Usage

  1. if ( !function_exists( 'get_post_custom_keys' ) ) { 
  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_keys($post_id); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function get_post_custom_keys( $post_id = 0 ) { 
  2. $custom = get_post_custom( $post_id ); 
  3.  
  4. if ( !is_array($custom) ) 
  5. return; 
  6.  
  7. if ( $keys = array_keys($custom) ) 
  8. return $keys;