WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get transient

Contents

Description

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.

Usage

<?php get_transient$transient ); ?>

Parameters

$transient
(string) (required) Unique transient name (this should be 45 characters or less in length. NOTE: if using a site transient, it should be 40 characters or less in length). Expected to not be SQL-escaped.
Default: None

Return Values

(mixed) 
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.

Examples

Example of using get_transient, set_transient and WP_Query

<?php
// 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 the data like you would have normally...
?>

Notes

Change Log

Since: 2.8

Source File

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

Related

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.