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.

get_post_field() 描述

用法

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

get_post_field() 用法

参数

$field

(string) (必填) Post field name

默认值: None

Any field from the *_posts table:

  • post_content
  • post_author
  • post_title
  • post_name (=slug)
  • etc.

$post_id

(id) (必填) Post ID

默认值: None

$context

(string) (可选) 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.

默认值: display

get_post_field() 参数

返回值

(WP_Error|string

Value in post field or a WP_Error object on failure

get_post_field() 返回值

注意

  • get_post_field() fetches the whole post using get_post(). So there is no performance advantage.

get_post_field() 注意

历史

添加于 版本: 2.3

get_post_field() 历史

源文件

get_post_field() 函数的代码位于 wp-includes/post.php

get_post_field() 源文件