Advertisements

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

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: