WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/register meta

Description

Registers meta key. This is for use with WordPress's various APIs as well as the custom post fields box. If you want to create custom UI, you will need to use add_meta_box.

Usage

 <?php 
$args = array(
    'sanitize_callback' => 'sanitize_my_meta_key',
    'auth_callback' => 'authorize_my_meta_key',
    'type' => 'string',
    'description' => 'My registered meta key',
    'single' => true,
    'show_in_rest' => true,
);
register_meta( 'post', 'my_meta_key', $args );  ?> 

Parameters

$object_type
(string) (required) Type of object this meta is registered to.
Default: None
$meta_key
(string) (required) The meta field key.
Default: None
$args
(array) (required) An array of arguments.
Default: None

Arguments

sanitize_callback
(string) (optional) A function or method to call when sanitizing `$meta_key` data.
Default: null
auth_callback
(string) (optional) A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks.
Default: null
type
(string) (optional) The type of data associated with this meta key. E.g. "string" or "integer"
Default: "string"
description
(string) (optional) A description of the data attached to this meta key.
Default: ""
single
(boolean) (optional) Whether the meta key has one value per object, or an array of values per object.
Default: false
$show_in_rest
(boolean) (optional) Whether data associated with this meta key can be considered public.
Default: false

Return

(boolean) 
True if the meta key was successfully registered in the global array, false if not.

Examples

Source Code

register_meta() is located in wp-includes/meta.php

Related

Custom Fields: the_meta(), get_post_meta(), add_post_meta(), update_post_meta(), delete_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys() (See Also: post_meta Function Examples)

See also index of Function Reference and index of Template Tags.