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.


  • 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);



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: Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: