为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
缥缈止盈 2023-10-01 16:01:43
我刚刚更新到 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 日,仍在寻找解决方案。
查看完整描述

2 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

WP 5.5在没有必需参数或使用不正确值的情况下调用时开始抛出通知rest_validate_value_from_schema()type属性的允许值为'array', 'object', 'string', 'number', 'integer', 'boolean', 'null'

您共享的代码不会对我产生任何错误,因此问题可能出在您未共享的某些代码中?如果您要注册一个带有属性的块,那么每个属性都需要一个type参数。

查看完整回答
反对 回复 2023-10-01
?
不负相思意

TA贡献1777条经验 获得超10个赞

试试这个 - 停用所有插件并刷新,看看它是否有效。如果是,则一一安装插件,并在每次插件安装后刷新。如果您找到导致问题的插件,请将其删除。



查看完整回答
反对 回复 2023-10-01
  • 2 回答
  • 0 关注
  • 58 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信