Home » Functions » register_meta

The register_meta function in WordPress is used to register a meta key for a specific object type (post type, user, term, etc.). This function allows developers to define custom meta data for their WordPress objects, which can then be used to store additional information related to those objects.

By registering a meta key, you are essentially telling WordPress to recognize and store this custom meta data when it is associated with the specified object type. This meta data can then be retrieved and displayed on the front end of the website or used in the backend for various purposes, such as filtering, sorting, or displaying additional information.

Example usage code:

register_meta( 'post', 'custom_meta_key', array(
    'type' => 'string',
    'description' => 'Custom meta data for posts',
    'single' => true,
    'show_in_rest' => true,
) );

In this example, we are registering a custom meta key called custom_meta_key for the post object type. We specify the data type as a string, provide a description for the meta key, indicate that it is a single value (not an array), and allow it to be displayed in the REST API. This registered meta key can now be used to store and retrieve custom meta data for posts on the WordPress site.

Learn More on

Register an account to save your snippets or go Pro to get more features.