Caching WordPress data using Transients - Example
In this simple example we create a function for obtaining data from an external source and caching it for 24 hours. You can use the function
hd_get_external_data() to get the data and work with it in your site.
If you want to force a refresh of the cache, you can pass a value of
true into the function.
You can place the code into your themes
functions.php file or better still in a plugin. If you are placing it in a plugin, remember to use
function_exists() when using this. This ensures that the code will fail correctly if the plugin is not active.