WordPress获取文章元数据键函数:get_post_custom_keys

WordPress函数get_post_custom_keys用于获取文章所有元数据的键。

get_post_custom_keys( int $post_id )

函数参数

$post_id

整数,默认值:当前文章ID

文章的ID

函数返回值

文章的自定义字段不同,返回的结果也有所不同:

Array
(
    [0] => _edit_last
    [1] => _thumbnail_id
    [2] => _edit_lock
    [3] => views
    [4] => _wp_page_template
    [5] => _encloseme
)

函数使用示例

以下示例排除了系统自带的meta,也就是仅返回用户自定义字段:

$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
    $valuet = trim($value);
    if ( '_' == $valuet{0} )
        continue;
    echo $key . " => " . $value . "<br />";
}

扩展阅读

get_post_custom_keys()函数位于:wp-includes/post.php

相关函数:

阿里云