Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get transient


Get the value of a transient.

If the transient does not exist or does not have a value, then the return value will be false.


<?php get_transient$transient ); ?>


(string) (required) Unique transient name. Expected to not be SQL-escaped. Should be 172 characters or less in length as WordPress will prefix your name with "_transient_" or "_transient_timeout_" in the options table (depending on whether it expires or not). Longer key names will silently fail. See Trac #15058.
Default: None

Return Values

Value of transient. If the transient does not exist, does not have a value, or has expired, then get_transient will return false. This should be checked using the identity operator ( === ) instead of the normal equality operator, because an integer value of zero (or other "empty" data) could be the data you're wanting to store. Because of this "false" value, transients should not be used to hold plain boolean values. Put them into an array or convert them to integers instead.


Example of using get_transient, set_transient and WP_Query

// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
  // It wasn't there, so regenerate the data and save the transient
  $special_query_results = new WP_Query( 'cat=5&order=random&tag=tech&post_meta_key=thumbnail' );
  set_transient( 'special_query_results', $special_query_results );

// Use `$special_query_results` like you would have normally...


Change Log

Since: 2.8

Source File

get_transient() is located in wp-includes/option.php.


Transients API: set_transient(), get_transient(), delete_transient(), set_site_transient(), get_site_transient(), delete_site_transient()

See also index of Function Reference and index of Template Tags.