WordPress函数get_post_custom_keys()通过id获取文章/页面所有的自定义字段(post meta)的键(key)

描述:

通过id获取文章/页面所有的自定义字段(post meta)的键(key)

用法:

 <?php get_post_custom_keys($post_id); ?> 

参数:

$post_id

(integer) (可选) 将检索其自定义字段键的文章 ID。

默认值: 当前文章

示例:

<?php

$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 />";
}
?>

源文件:

/**
 * Retrieve meta field names for a post.
 *
 * If there are no meta fields, then nothing (null) will be returned.
 *
 * @since 1.2.0
 *
 * @param int $post_id Optional. Post ID. Default is ID of the global $post.
 * @return array|void Array of the keys, if retrieved.
 */
function get_post_custom_keys( $post_id = 0 ) {
	$custom = get_post_custom( $post_id );

	if ( !is_array($custom) )
		return;

	if ( $keys = array_keys($custom) )
		return $keys;
}