get_metadata_by_mid( string $meta_type, int $meta_id )

Retrieves metadata by meta ID.


Parameters

$meta_type

(Required) Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.

$meta_id

(Required) ID for a specific meta row.


Return

(stdClass|false) Metadata object, or boolean false if the metadata doesn't exist.<br>

  • 'meta_key'
    (string) The meta key.<br>
  • 'meta_value'
    (mixed) The unserialized meta value.<br>
  • 'meta_id'
    (string) Optional. The meta ID when the meta type is any value except 'user'.<br>
  • 'umeta_id'
    (string) Optional. The meta ID when the meta type is 'user'.<br>
  • 'post_id'
    (string) Optional. The object ID when the meta type is 'post'.<br>
  • 'comment_id'
    (string) Optional. The object ID when the meta type is 'comment'.<br>
  • 'term_id'
    (string) Optional. The object ID when the meta type is 'term'.<br>
  • 'user_id'
    (string) Optional. The object ID when the meta type is 'user'.<br>


Source

File: wp-includes/meta.php

function get_metadata_by_mid( $meta_type, $meta_id ) {
	global $wpdb;

	if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
		return false;
	}

	$meta_id = intval( $meta_id );
	if ( $meta_id <= 0 ) {
		return false;
	}

	$table = _get_meta_table( $meta_type );
	if ( ! $table ) {
		return false;
	}

	$id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';

	$meta = $wpdb->get_row( $wpdb->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;
}


Changelog

Changelog
Version Description
3.3.0 Introduced.