Last modified by - 9 years ago
2504 Views
Less than a minute read

How to get error message when using wp_remote_post and wp_remote_get

When using WordPress HTTP API, if the connection fails you could use the below code to display the error message.

$response = wp_remote_post($url);
if (is_wp_error($response)) {
$error = $response->get_error_message();
echo $error;
} else {
$content = wp_remote_retrieve_body($response);
}
view raw gistfile1.txt hosted with ❤ by GitHub

Both wp_remote_post and wp_remote_get return WP_Error object if there is an error.  You could use the get_error_message function of WP_Error class to receive the error and show it.

Related Embeds
Previous Next
Related Panels
Related Articles
Related Documents
Previous Next
Was this information helpful?