get_post_field
函数
get_post_field ( $field, $post = null, $context = 'display' )
- 参数
-
-
(string)
$field
Post field name.- Required: 是
-
(int|WP_Post)
$post
Optional. Post ID or post object. Defaults to global $post.- Required: 否
- Default: null
-
(string)
$context
Optional. How to filter the field. Accepts ‘raw’, ‘edit’, ‘db’, or ‘display’. Default ‘display’.- Required: 否
- Default: ‘display’
-
(string)
- 返回值
-
- (string) The value of the post field on success, empty string on failure.
- 相关
-
- sanitize_post_field()
- 定义位置
-
-
wp-includes/post.php
, line 1079
-
wp-includes/post.php
- 引入
- 2.3.0
- 弃用
- –
根据帖子ID从一个文章字段中检索数据。
文章字段的例子有:”post_type”、”post_status”、”post_content “等,并基于文章对象的属性或键名。
上下文的值是基于分类法的过滤功能,支持的值可以在这些功能中找到。
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 ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。