وردپرس

Error 400 when publishing a post from a custom post type


I have a custom post type, where when I try to publish a post of that type WordPress gives me an error “The editor has encountered an unexpected error.”, while JavaScript returns an error 400 Bad Request, while debug.log gets no output. Clicking on “Copy post text” and “Copy error” only copies other JavaScript errors, but they do not prevent the request from being sent.

Here is some data from developer tools:
The request payload:

{id: 950, status: "publish", content: ""}

The response:

{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): status",
    "data": {
        "status": 400,
        "params": {
            "status": "status[0] is not of type integer."
        },
        "details": {
            "status": {
                "code": "rest_invalid_type",
                "message": "status[0] is not of type integer.",
                "data": {
                    "param": "status[0]"
                }
            }
        }
    }
}

The weird part, is that when I create a new page and check the payload, the “status” is also sent as a string, but the publishing is successful.

Here is also the definition of the custom post type:

register_post_type( 'property',
    array(
        'labels' => array(
            'name' => __( 'Properties' ),
            'singular_name' => __( 'Property' ),
            'add_new_item' => __( 'Add property' ),
            'all_items' => __( 'All properties' ),
         ),
         'has_archive' => true,
         'public' => true,
         'rewrite' => array('slug' => 'parceli'),
         'show_in_rest' => true,
         'supports' => array('editor', 'title', 'thumbnail'),
         'menu_icon' => 'dashicons-post-status',
         'map_meta_cap' => true,
         'rest_controller_class' => 'WP_REST_Posts_Controller',
     )
);

I tried disabling all the plugins – error persists. I have enabled logging to debug.log, but like I said – nothing comes up there. Using Chat GPT for help, it recommended me to use a few filters for debugging (rest_pre_dispatch, rest_pre_serve_request), but nothing gets outputted.

این خبر را در ایران وب سازان مرجع وب و فناوری دنبال کنید

مشاهده پاسخ های این مطلب
———————————————
این مطلب از سایت انجمن وردپرس گردآوری شده است و کلیه حقوق مطلق به انجمن وردپرس می باشد در صورت مغایرت و یا بروز مشکل اطلاع دهید تا حذف گردد

منبع: انجمن وردپرس

دکمه بازگشت به بالا