get_post_field()

最后更新于:2021-11-26 22:30:42

get_post_field( string$field, int|GC_Post$post=null, string$context=’display’)

Retrieve data from a post field based on Post ID.

参数

$field

(string) (Required) Post field name.

$post

(int|GC_Post) (Optional) Post ID or post object. Defaults to global $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.

源文件

文件: gc-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 );
}
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