WordPress函数 get_post_field 是用来获取文章的字段的。
函数源码:
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 );
}
从源码上看,这个函数也是先用 get_post 函数查询文章,然后读取相应的字段。相对于直接读取,这个采用的是 sanitize_post_field 函数。
从源码上也可以看出,get_post_field 的 $field 是区分大小写的。
get_post_field('ID'); // 返回当前文章的 ID
get_post_field('id'); // 返回空字符串
$post的全部字段都是支持的:
ID
post_author
post_date
post_date_gmt
post_content
post_title
post_excerpt
post_status
comment_status
ping_status
post_password
post_name
to_ping
pinged
post_modified
post_modified_gmt
post_content_filtered
post_parent
guid
menu_order
post_type
post_mime_type
comment_count
filter
……
-
WordPress函数:get_template_part 用法简介get_template_part 有什么优点
-
WordPress函数:wp_is_writable 判断路径是否可写检查文件权限的方便函数
-
WordPress函数:wp_title 主题页面标题WordPress 页面标题SEO
-
WordPress函数:wp_timezone_string 返回后台设置的时区当前设置的时区是什么
-
WordPress函数:current_time 返回当前时间在 WordPress 如何获取当前时间
-
WordPress函数:set_query_var 与 get_query_var 设置与获取查询参数一对WordPress函数
暂无评论,抢个沙发...