get_post_meta

函数
get_post_meta ( $post_id, $key = '', $single = false )
参数
  • (int) $post_id Post ID.
    Required:
  • (string) $key Optional. The meta key to retrieve. By default, returns data for all keys. Default empty.
    Required:
    Default: (empty)
  • (bool) $single Optional. Whether to return a single value. This parameter has no effect if `$key` is not specified. Default false.
    Required:
    Default: false
返回值
  • (mixed) An array of values if `$single` is false. The value of the meta field if `$single` is true. False for an invalid `$post_id` (non-numeric, zero, or negative value). An empty string if a valid but non-existing post ID is passed.
定义位置
相关方法
get_site_metaget_post_timeget_post_timestampdelete_post_metaget_post_meta_by_id
引入
1.5.0
弃用
-

get_post_meta函数检索特定post-meta字段的值。它有三个参数:第一个参数是文章的ID,第二个参数是元字段的名称,第三个参数是一个布尔值,指示检索到的值应该是单个值还是一个值数组。

为给定的文章ID检索一个文章元字段。

function get_post_meta( $post_id, $key = '', $single = false ) {
	return get_metadata( 'post', $post_id, $key, $single );
}

常见问题

FAQs
查看更多 >