Uses
Uses | Description |
---|---|
wp-includes/post.php: sanitize_post_field() | Sanitizes a post field based on context. |
wp-includes/post.php: get_post() | Retrieves post data given a post ID or post object. |
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.
The context values are based off of the taxonomy filter functions and supported values are found within those functions.
(string) (Required) Post field name.
(int|WP_Post) (Optional) Post ID or post object. Defaults to global $post.
Default value: null
(string) (Optional) How to filter the field. Accepts 'raw', 'edit', 'db', or 'display'.
Default value: 'display'
(string) The value of the post field on success, empty string on failure.
File: wp-includes/post.php
function get_post_field( $field, $post = null, $context = 'display' ) { $post = get_post( $post ); if ( ! $post ) { return ''; } if ( ! isset( $post->$field ) ) { return ''; } return sanitize_post_field( $field, $post->$field, $post->ID, $context ); }
Version | Description |
---|---|
4.5.0 | The $post parameter was made optional. |
2.3.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_field