The get_registered_metadata() WordPress PHP function retrieves registered metadata for a specified object.
Usage
get_registered_metadata($object_type, $object_id, $meta_key = '');
Parameters
- $object_type (string) – Type of object metadata is for. Accepts ‘post’, ‘comment’, ‘term’, ‘user’, or any other object type with an associated meta table.
- $object_id (int) – ID of the object the metadata is for.
- $meta_key (string, optional) – Registered metadata key. If not specified, retrieves all registered metadata for the specified object. Default: ”
More information
See WordPress Developer Resources: get_registered_metadata()
Examples
Retrieve all registered metadata for a post
$post_id = 42; // Post ID $metadata = get_registered_metadata('post', $post_id);
Retrieve all registered metadata for a user
$user_id = 7; // User ID $metadata = get_registered_metadata('user', $user_id);
Retrieve a specific metadata value for a comment
$comment_id = 13; // Comment ID $meta_key = 'rating'; // Metadata key $metadata = get_registered_metadata('comment', $comment_id, $meta_key);
Retrieve all registered metadata for a term
$term_id = 5; // Term ID $metadata = get_registered_metadata('term', $term_id);
Retrieve a specific metadata value for a custom object type
$object_type = 'custom_type'; // Custom object type $object_id = 1; // Object ID $meta_key = 'custom_key'; // Metadata key $metadata = get_registered_metadata($object_type, $object_id, $meta_key);