Cache WP remote_get HTTP Response using Transients
function display_api_response() { $body = get_transient( ‘my_remote_response_value’ ); if ( false === $body ) { $api_url = “https://randletter2020.herokuapp.com”; $response = wp_remote_get($api_url); if (200 !== wp_remote_retrieve_response_code($response)) { return; } $body = wp_remote_retrieve_body($response); set_transient( ‘my_remote_response_value’, $body, 5*MINUTE_IN_SECONDS ); } if (‘a’ === $body) { echo ‘A wins’; } else { // Do something else. } } add_action(‘init’, … Read more