get_metadata
函数
get_metadata ( $meta_type, $object_id, $meta_key = '', $single = false )
- 参数
-
-
(string)
$meta_type
Type of object metadata is for. Accepts ‘post’, ‘comment’, ‘term’, ‘user’, or any other object type with an associated meta table.- Required: 是
-
(int)
$object_id
ID of the object metadata is for.- Required: 是
-
(string)
$meta_key
Optional. Metadata key. If not specified, retrieve all metadata for the specified object. Default empty.- Required: 否
- Default: (empty)
-
(bool)
$single
Optional. If true, return only the first value of the specified `$meta_key`. This parameter has no effect if `$meta_key` is not specified. Default false.- Required: 否
- Default: false
-
(string)
- 返回值
-
- (mixed) An array of values if `$single` is false. The value of the meta field if `$single` is true. False for an invalid `$object_id` (non-numeric, zero, or negative value), or if `$meta_type` is not specified. An empty string if a valid but non-existing object ID is passed.
- 相关
-
- get_metadata_raw()
- get_metadata_default()
- 定义位置
-
-
wp-includes/meta.php
, line 570
-
wp-includes/meta.php
- 引入
- 2.9.0
- 弃用
- –
检索指定对象类型和ID的元数据字段的值。
如果元数据字段存在,如果`$single`为真,则返回一个单一的值,如果为假,则返回一个数组的值。
如果元字段不存在,其结果取决于get_metadata_default()。默认情况下,如果`$single`为真,将返回一个空字符串,如果为假,将返回一个空数组。
function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false ) { $value = get_metadata_raw( $meta_type, $object_id, $meta_key, $single ); if ( ! is_null( $value ) ) { return $value; } return get_metadata_default( $meta_type, $object_id, $meta_key, $single ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。