A WordPress-centric search engine for devs and theme authors



get_registered_metadata ›

Since4.6.0
Deprecatedn/a
get_registered_metadata ( $object_type, $object_id, $meta_key = '' )
Parameters: (3)
  • (string) $object_type Type of object to request metadata for. (e.g. comment, post, term, user)
    Required: Yes
  • (int) $object_id ID of the object the metadata is for.
    Required: Yes
  • (string) $meta_key Optional. Registered metadata key. If not specified, retrieve all registered metadata for the specified object.
    Required: No
    Default: (empty)
Returns:
  • (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.
Defined at:
Codex:

Retrieves registered metadata for a specified object.



Source

function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) {
	if ( ! empty( $meta_key ) ) {
		if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) {
			return false;
		}
		$meta_keys     = get_registered_meta_keys( $object_type );
		$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 );

	$meta_keys       = get_registered_meta_keys( $object_type );
	$registered_data = array();

	// Someday, array_filter()
	foreach ( $meta_keys as $k => $v ) {
		if ( isset( $data[ $k ] ) ) {
			$registered_data[ $k ] = $data[ $k ];
		}
	}

	return $registered_data;
}