WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get post field

Contents

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 *_post table:

  • post_content
  • post_author
  • post_title
  • 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

(WP_Error|string) 
Value in post field or a WP_Error object on failure

Change Log

Since: 2.3

Source File

get_post_field() is located in wp-includes/post.php

Related

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