Languages:
English •
Italiano •
日本語
(Add your language)
Description
Retrieve data from a post field based on post ID.
Examples of post fields are 'post_type', 'post_status', 'post_content', or any of the other fields of the posts table in the database.
The field will be filtered based on the $context.
Usage
<?php get_post_field( $field, $post_id, $context ); ?>
Parameters
- $field
- (string) (required) Post field name
- Default: None
Any field from the *_posts table:
- post_content
- post_author
- post_title
- post_name (=slug)
- etc.
- $post_id
- (id) (required) Post ID
- Default: None
- $context
- (string) (optional) Optional. How to filter the field. Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display' when calling filters.
- Default: display
Return Values
- (string)
- The value of the post field on success, empty string on failure.
Change Log
Since: 2.3
Notes
- get_post_field() fetches the whole post using get_post(). So there is no performance advantage.
Source File
get_post_field() is located in wp-includes/post.php
Related
- get_post() - Retrieve all post fields for a post by ID.