时间:2024-03-09
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
相关函数:
get_post_custom()
get_post_custom_values()
the_meta()
get_post_meta()
Copyright © 2019-2024 79956.com