Last active
July 3, 2020 21:28
-
-
Save domosedov/2bb90034b5b17c04e5a819726a900aef to your computer and use it in GitHub Desktop.
Wordpress register array type meta example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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