如何修复WordPress 5.5中的Rest API错误?

问题描述

我刚刚更新到WordPress 5.5,并且在调试模式下出现错误。

rest_validate_value_from_schema was called incorrectly. The "type" schema keyword for [0] can only be one of the built-in types: array,object,string,number,integer,boolean,and null. Please see Debugging in WordPress for more information. 

我正在使用自定义端点来创建一些自定义块。

function example_custom_route()
{
register_rest_route('example/v1','posts',[
    'methods' => WP_REST_Server::READABLE,'callback' => 'example_result_posts','permission_callback' => function () {
        return current_user_can( 'edit_posts' );
    }
]);
}
add_action('rest_api_init','example_custom_route');

function example_result_posts()
{
    $posts_result = [];
    $post_type = 'post';

    $posts = get_posts([
        'post_type' => $post_type,'order' => 'DESC','orderby' => 'date','ignore_sticky_posts' => 1,'posts_per_page' => -1,'post_status' => 'publish'
    ]);
    if (!empty($posts)) {
        foreach ($posts as $post) {
            array_push($posts_result,[
                'value' => $post->ID,'label' => wp_specialchars_decode(wp_strip_all_tags($post->post_title)),]);
        }
        wp_reset_postdata();
    }
    return $posts_result;
}

什么是““类型”架构关键字”,我该如何解决?

在8月14日仍在寻找这个...的孤岛。

解决方法

WP 5.5 started throwing notices when rest_validate_value_from_schema() is called without required parameters,or with incorrect valuestype属性的允许值为'array','object','string','number','integer','boolean','null'

您共享的代码不会对我产生任何错误,因此可能是您未共享的某些代码出了问题?如果要注册具有属性的块,则each attribute will need a type parameter

在旁边:有a dedicated WordPress Stack Exchange。将来您可能会在那得到更好的答复。

,

尝试一下-停用所有插件,然后刷新并查看其是否有效。如果是,则一个接一个地安装插件,并在每次安装插件后刷新。如果找到引起问题的插件,请删除它。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...