Is it possible to send HTTP status codes other than 200 OK with `wp_send_json_error()`?

Responsive Ad Header

Question

Grade: Education Subject: Support
Is it possible to send HTTP status codes other than 200 OK with `wp_send_json_error()`?
Asked by:
87 Viewed 87 Answers

Answer (87)

Best Answer
(351)
While `wp_send_json_error()` defaults to a 200 OK status code, you can modify the HTTP status code using the `wp_send_json_error()`'s third optional parameter. For example, `wp_send_json_error( 'Invalid data', 400 );` will send a 400 Bad Request status code along with the error message. This is useful for indicating the type of error to the client.