get_post_field

Definition:
function get_post_field( $field, $post, $context = 'display' ) {}

Retrieve data from a post field based on Post ID.
Examples of the post field will be, ‘post_type’, ‘post_status’, ‘post_content’, etc and based off of the post object property or key names.

Parameters

  • string $field: Post field name
  • id $post: Post ID
  • string $context: Optional. How to filter the field. Default is display.

Return values

returns:Value in post field or WP_Error on failure

Source code

function get_post_field( $field, $post, $context = 'display' ) {

	$post = (int) $post;

	$post = get_post( $post );



	if ( is_wp_error($post) )

		return $post;



	if ( !is_object($post) )

		return '';



	if ( !isset($post->$field) )

		return '';



	return sanitize_post_field($field, $post->$field, $post->ID, $context);

}

1591

get_post_custom_values

Definition:
function get_post_custom_values( $key = '', $post_id = 0 ) {}

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

Parameters

  • string $key: Meta field key.
  • int $post_id: Post ID

Return values

returns:Meta field values.

Source code

function get_post_custom_values( $key = '', $post_id = 0 ) {

	if ( !$key )

		return null;



	$custom = get_post_custom($post_id);



	return isset($custom[$key]) ? $custom[$key] : null;

}

1589

get_post_custom_keys

Definition:
function get_post_custom_keys( $post_id = 0 ) {}

Retrieve meta field names for a post.
If there are no meta fields, then nothing (null) will be returned.

Parameters

  • int $post_id: post ID

Return values

returns:Either array of the keys, or null if keys could not be retrieved.

Source code

function get_post_custom_keys( $post_id = 0 ) {

	$custom = get_post_custom( $post_id );



	if ( !is_array($custom) )

		return;



	if ( $keys = array_keys($custom) )

		return $keys;

}

1587