亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復 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 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號