返回介绍

get_post_field()

发布于 2017-09-10 23:51:24 字数 2299 浏览 1086 评论 0 收藏 0

get_post_field( string $field,  int|WP_Post $post = null,  string $context = 'display' )

Retrieve data from a post field based on Post ID.


description

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.


参数

$field

(string) (Required) Post field name.

$post

(int|WP_Post) (Optional) Post ID or post object. Defaults to current post.

Default value: null

$context

(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);
}

更新日志

Versiondescription
4.5.0The $post parameter was made optional.
2.3.0Introduced.

相关函数

Uses

  • wp-includes/post.php: sanitize_post_field()
  • wp-includes/post.php: get_post()

Used By

  • wp-admin/includes/post.php: _wp_translate_postdata()
  • wp-includes/post.php: wp_insert_post()
  • wp-includes/nav-menu.php: wp_update_nav_menu_item()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文