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
No comments yet... Be the first to leave a reply!