First of all, it's best not to include wp-blog-header.php
. Instead, set the cron job to your homepage URL with a ?mycustomcron=true
variable appended (eg: http://example.com/?mycustomcron=true
. Then we will check for the existance of this variable when the page loads:
function wpse_103127_check_cron() {
if ( isset( $_GET['mycustomcron'] ) ) {
// things to do on cron here
exit; // no need to load the page on cron
}
}
add_action( 'template_redirect', 'wpse_103127_check_cron' );
As for saving the data for later access in WordPress, you can save the data to the wp_options
table:
$exchange_rates = getExchangeRates();
update_option( 'exchange_rates', $exchange_rates );
And then access it later:
$exchange_rates = get_option( 'exchange_rates' );
See the Options API Codex article for more information about saving data to the database.