Using WordPress ‘get_registered_meta_keys()’ PHP function

The get_registered_meta_keys() WordPress PHP function retrieves a list of registered metadata arguments for an object type, keyed by their meta keys.

Usage

get_registered_meta_keys( $object_type, $object_subtype = '' );

Parameters

  • $object_type (string) (required) – Type of object metadata is for. Accepts ‘post’, ‘comment’, ‘term’, ‘user’, or any other object type with an associated meta table.
  • $object_subtype (string) (optional) – The subtype of the object type. Default: ”

More information

See WordPress Developer Resources: get_registered_meta_keys()

Examples

Get registered meta keys for posts

In this example, we retrieve the registered meta keys for posts.

// Get the registered meta keys for 'post' object type
$registered_meta_keys = get_registered_meta_keys( 'post' );

// Output the registered meta keys
foreach ( $registered_meta_keys as $key => $value ) {
    echo "Key: " . $key . "\n";
}

Get registered meta keys for a custom post type

In this example, we retrieve the registered meta keys for a custom post type called ‘product’.

// Get the registered meta keys for 'post' object type with 'product' subtype
$registered_meta_keys = get_registered_meta_keys( 'post', 'product' );

// Output the registered meta keys
foreach ( $registered_meta_keys as $key => $value ) {
    echo "Key: " . $key . "\n";
}

Get registered meta keys for users

In this example, we retrieve the registered meta keys for users.

// Get the registered meta keys for 'user' object type
$registered_meta_keys = get_registered_meta_keys( 'user' );

// Output the registered meta keys
foreach ( $registered_meta_keys as $key => $value ) {
    echo "Key: " . $key . "\n";
}

Get registered meta keys for terms

In this example, we retrieve the registered meta keys for terms.

// Get the registered meta keys for 'term' object type
$registered_meta_keys = get_registered_meta_keys( 'term' );

// Output the registered meta keys
foreach ( $registered_meta_keys as $key => $value ) {
    echo "Key: " . $key . "\n";
}

Get registered meta keys for comments

In this example, we retrieve the registered meta keys for comments.

// Get the registered meta keys for 'comment' object type
$registered_meta_keys = get_registered_meta_keys( 'comment' );

// Output the registered meta keys
foreach ( $registered_meta_keys as $key => $value ) {
    echo "Key: " . $key . "\n";
}