首页 WordPress函数大全 get_post_field()

get_post_field()

2020-05-01 / 3358阅 / 悠然

如何你看完本文还不知道如何使用该函数,可以联系我定制视频教程,50元/个函数,学不会全额退款

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

基于post字段检索数据,根据文章ID或者对象获取posts表中的字段

描述

post字段的例子有' post_type '、' post_status '、' post_content '等,并且基于post对象属性或键名。上下文值基于分类法筛选器函数,支持的值可以在这些函数中找到。

参阅
See also

  • sanitize_post_field()

参数

$field

(string)
(必须)
字段名称

$post

(int|WP_Post)
(必须)
文章ID或者文章对象,当前文章对象

默认值: null

$context

(string)
(选填)
如何过滤字段. 支持'raw', 'edit', 'db', or 'display'.

默认: 'display'

返回

(string) 成功时返回字符串的值,失败返回空.

示例

获取文章作者:

<?php
       echo  get_post_field('post_type',get_the_ID());
       echo  get_post_field('post_author',get_the_ID());
       echo  get_post_field('post_content',get_the_ID());
       echo  get_post_field('post_type',get_the_ID());
       echo  get_post_field('post_type',get_the_ID());
?>               
大家谈论
    我的见解