Skip to content

Instantly share code, notes, and snippets.

@domosedov
Last active July 3, 2020 21:28
Show Gist options
  • Save domosedov/2bb90034b5b17c04e5a819726a900aef to your computer and use it in GitHub Desktop.
Save domosedov/2bb90034b5b17c04e5a819726a900aef to your computer and use it in GitHub Desktop.
Wordpress register array type meta example
register_meta(
'user',
'user_friends_list',
[
'object_subtype' => 'user',
'type' => 'array',
'description' => 'Friends Ids',
'single' => true,
'sanitize_callback' => null,
'auth_callback' => 'null',
'show_in_rest' => [
'schema' => [
'type' => 'array',
'items' => [
'type' => 'integer'
]
]
],
]
);
register_meta(
'user',
'info',
[
'single' => true,
'type' => 'object',
'show_in_rest' => [
'schema' => [
'type' => 'object',
'properties' => [
'age' => [
'type' => 'integer',
],
'gender' => [
'type' => 'string',
],
'admin' => [
'type' => 'boolean'
]
],
],
],
]
);
register_meta(
'user',
'todos',
[
'single' => true,
'type' => 'array',
'show_in_rest' => [
'schema' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'text' => [
'type' => 'string',
],
'completed' => [
'type' => 'boolean'
]
],
]
]
]
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment