Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post field


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.


<?php get_post_field$field$post_id$context ); ?>


(string) (required) Post field name
Default: None

Any field from the *_posts table:

  • post_content
  • post_author
  • post_title
  • post_name (=slug)
  • etc.
(id) (required) Post ID
Default: None
(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

The value of the post field on success, empty string on failure.

Change Log

Since: 2.3


  • 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


  • get_post() - Retrieve all post fields for a post by ID.