get_metadata_by_mid()
最后更新于:2021-11-26 09:33:21
get_metadata_by_mid( string$meta_type, int$meta_id)Retrieves metadata by meta ID.
参数
- $meta_type
-
(string) (Required) Type of object metadata is for. Accepts ‘post’, ‘comment’, ‘term’, ‘user’, or any other object type with an associated meta table.
- $meta_id
-
(int) (Required) ID for a specific meta row.
响应
(stdClass|false) Metadata object, or boolean false
if the metadata doesn’t exist.
-
‘meta_key’
(string) The meta key. -
‘meta_value’
(mixed) The unserialized meta value. -
‘meta_id’
(string) Optional. The meta ID when the meta type is any value except ‘user’. -
‘umeta_id’
(string) Optional. The meta ID when the meta type is ‘user’. -
‘post_id’
(string) Optional. The object ID when the meta type is ‘post’. -
‘comment_id’
(string) Optional. The object ID when the meta type is ‘comment’. -
‘term_id’
(string) Optional. The object ID when the meta type is ‘term’. -
‘user_id’
(string) Optional. The object ID when the meta type is ‘user’.
源文件
文件: gc-includes/meta.php
function get_metadata_by_mid( $meta_type, $meta_id ) {
global $gcdb;
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
return false;
}
$meta_id = (int) $meta_id;
if ( $meta_id <= 0 ) {
return false;
}
$table = _get_meta_table( $meta_type );
if ( ! $table ) {
return false;
}
/**
* Short-circuits the return value when fetching a meta field by meta ID.
*
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
* (post, comment, term, user, or any other type with an associated meta table).
* 响应ing a non-null value will effectively short-circuit the function.
*
* @since 5.0.0
*
* @param stdClass|null $value The value to return.
* @param int $meta_id Meta ID.
*/
$check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id );
if ( null !== $check ) {
return $check;
}
$id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id';
$meta = $gcdb->get_row( $gcdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) );
if ( empty( $meta ) ) {
return false;
}
if ( isset( $meta->meta_value ) ) {
$meta->meta_value = maybe_unserialize( $meta->meta_value );
}
return $meta;
}