[ad_1]
I want to register metadata for a complex data type with the following structure:
[
{
"mediaType": "image",
"mediaID": "36",
"respnsive": [
{
"mediaType": "image",
"mediaID": "36",
"rule": {
"client": "desktop",
"ratio": "landscape"
}
}
]
},
{
"mediaType": "image",
"mediaID": "37",
"respnsive": [
{
"mediaType": "image",
"mediaID": "38",
"rule": {
"client": "desktop",
"ratio": "landscape"
}
}
]
},
...
]I registered using the following method:
register_meta(
'post',
'_mk_post_thumbnail',
array(
'single' => false,
'type' => 'array',
'show_in_rest' => array(
'schema' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'theType' => array(
'type' => 'string',
),
),
),
),
),
'auth_callback' => function () {
return current_user_can('edit_posts');
}
)
);I get the value and update it use restapi
const value = useSelect( ( select ) => {
return select( 'core/editor' ).getEditedPostAttribute( 'meta' )?._mk_post_thumbnail;
} ) || [];
const handleItemAdd = () => {
const newValue = [ ...value ];
newValue.push( { mediaType: 'image' } );
editPost( {
meta: { _mk_post_thumbnail: newValue },
} );
};But when I try to save in gutenberg editor, it prompts me ‘Update failed. The type of meta._mk_post_thumbnail[0] is not an array.
