Viewing 1 replies (of 1 total)
  • Thread Starter Gnanasekaran Loganathan

    (@gnanasekaran)

    Use below function we can send HTTP status code

    return new WP_REST_Response($posts, 200);

    EX :

    $return = new WP_Error( ‘rest_cannot_edit_others’, __( ‘You are not allowed to create posts as this user.’ ), array( ‘status’ => rest_authorization_required_code() ) );

    $egr_reponse = array(‘error’ => $return->get_error_message());
    $code = $return->get_error_code();
    $status = $return->get_error_data($code);
    $status_code = $status[‘status’];
    return new WP_REST_Response($egr_reponse, $status_code);

Viewing 1 replies (of 1 total)
  • The topic ‘http status code in wp rest api’ is closed to new replies.