Skip to content

Instantly share code, notes, and snippets.

@sdunham
Created October 22, 2015 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdunham/255bb0d7558401fe2182 to your computer and use it in GitHub Desktop.
Save sdunham/255bb0d7558401fe2182 to your computer and use it in GitHub Desktop.
Caching With WordPress Transients
// Get any existing copy of our transient data, if one exists
if ( false === ( $foo = get_transient( 'foo_transient' ) ) ) {
// Nothing found, or transient expired. Regenerate it!
$foo = someExpensiveCodeOrQuery();
set_transient( 'foo_transient', $foo, 2*HOUR_IN_SECONDS );
}
// Use $foo somehow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment