get_registered_metadata
函数
get_registered_metadata ( $object_type, $object_id, $meta_key = '' )
- 参数
-
-
(string)
$object_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 the metadata is for.- Required: 是
-
(string)
$meta_key
Optional. Registered metadata key. If not specified, retrieve all registered metadata for the specified object.- Required: 否
- Default: (empty)
-
(string)
- 返回值
-
- (mixed) A single value or array of values for a key if specified. An array of all registered keys and values for an object ID if not. False if a given $meta_key is not registered.
- 定义位置
-
-
wp-includes/meta.php
, line 1680
-
wp-includes/meta.php
- 引入
- 4.6.0
- 弃用
- –
Retrieves registered metadata for a specified object.
The results include both meta that is registered specifically for the
object’s subtype and meta that is registered for the entire object type.
function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) { $object_subtype = get_object_subtype( $object_type, $object_id ); if ( ! empty( $meta_key ) ) { if ( ! empty( $object_subtype ) && ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { $object_subtype = ''; } if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { return false; } $meta_keys = get_registered_meta_keys( $object_type, $object_subtype ); $meta_key_data = $meta_keys[ $meta_key ]; $data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data['single'] ); return $data; } $data = get_metadata( $object_type, $object_id ); if ( ! $data ) { return array(); } $meta_keys = get_registered_meta_keys( $object_type ); if ( ! empty( $object_subtype ) ) { $meta_keys = array_merge( $meta_keys, get_registered_meta_keys( $object_type, $object_subtype ) ); } return array_intersect_key( $data, $meta_keys ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。