^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_post_field()用法示例

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

Retrieve data from a post field based on Post ID.


描述

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

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

更新日志

Version 描述
4.5.0 The $post parameter was made optional.
2.3.0 Introduced.

相关函数

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

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈