我已经在 register_post_meta 函数中注册了一个名为 project_description 的后元字段,它是显式的 'schema'。下面是register_post_meta函数-
function register_project_description_post_meta() {
register_block_type( plugin_dir_path( __FILE__) . 'build/project-description' );
register_post_meta('project', 'project_description', array(
'single' => true,
'type' => 'object',
'show_in_rest' => array(
'schema' => array(
'type' =>'object',
'properties' => array(
'excerpt' => array(
'type' => 'object',
'properties' => array(
'title' => array(
'type' => 'string'
),
'description' => array(
'type' => 'string'
)
)
),
'responsive' => array(
'type' => 'object',
'properties' => array(
'title' => array(
'type' => 'string'
),
'description' => array(
'type' => 'string'
),
'image' => array(
'type' => 'string',
'properties' => array(
'id' => array(
'type' => 'integer'
),
'url' => array(
'type' => 'string'
)
)
)
)
)
)
)
)
));
}
现在,当我将 image 属性更改为字符串类型而不是对象时,我在 Postman 中调用 REST API 时得到
project_description: null
。
所以我想知道当帖子已经有那个元字段时有没有办法改变模式。也就是说,在架构更改后,元字段应如下所示 -
project_description: {
excerpt: {
title: '',
description: '',
},
responsive: {
title: '',
description: '',
image: ''
}
}
代替
project_description: {
excerpt: {
title: '',
description: '',
},
responsive: {
title: '',
description: '',
image: {
id: '',
url: ''
}
}
}