WordPress函数get_post_meta()通过id获取文章/页面的自定义字段(post meta)信息

描述:

通过id获取文章/页面的自定义字段(post meta)信息

用法:

<?php  $key_1_value = get_post_meta( get_the_ID(), 'key_1', true );?>

参数:

$post_id

(int) (必填) 文章ID

$key

(string) (Optional) 要检索的metabox的键(key)

默认值: ”

$single

(bool) (选填) 如果为true,则只返回指定metabox的第一个值。如果未指定$key,则此参数无效。

默认值: false

源文件:

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