I’d recommend writing a simple plugin. Read through the Plugin Development Handbook, but it’s pretty easy. The only thing necessary for a plugin is the header with the Plugin Name.
In the plugin, create a function that gets and stores in a WordPress transient the result of an API request.
<?php
/**
* Plugin Name: WordPress StackExchange Question 266688
*/
namespace StackExchange\WordPress;
//* If you are running a version of PHP less than 5.3, namespaces are not available
//* Instead, you can pseudo-namespace the function
//* Simple function to use the transients API to cache the result of the external API request
function get() {
$transient = \get_transient( 'name_of_transient' );
if( ! empty( $transient ) ) {
return $transient;
}
$output = \wp_remote_get( 'https://api.example.com/v2/my-api/' );
\set_transient( 'name_of_transient', json_decode( $output ), DAY_IN_SECONDS );
return $out;
}
To use the function:
//* This will be an object
$api = \Stackexchange\WordPress\get();
echo $api->example_property;