get_transient

Get the value of a transient.

Description

get_transient( (string) $transient ); 

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

Parameters (1)

0. $transient (string)
Transient name. Expected to not be SQL-escaped.

Usage

  1. if ( !function_exists( 'get_transient' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // Transient name. Expected to not be SQL-escaped. 
  5. $transient = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_transient($transient); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function get_transient( $transient ) { 
  2.  
  3. /** 
  4. * Filters the value of an existing transient. 
  5. * The dynamic portion of the hook name, `$transient`, refers to the transient name. 
  6. * Passing a truthy value to the filter will effectively short-circuit retrieval 
  7. * of the transient, returning the passed value instead. 
  8. * @since 2.8.0 
  9. * @since 4.4.0 The `$transient` parameter was added 
  10. * @param mixed $pre_transient The default value to return if the transient does not exist. 
  11. * Any value other than false will short-circuit the retrieval 
  12. * of the transient, and return the returned value. 
  13. * @param string $transient Transient name. 
  14. */ 
  15. $pre = apply_filters( "pre_transient_{$transient}", false, $transient ); 
  16. if ( false !== $pre ) 
  17. return $pre; 
  18.  
  19. $value = wp_cache_get( $transient, 'transient' ); 
  20. } else { 
  21. $transient_option = '_transient_' . $transient; 
  22. if ( ! wp_installing() ) { 
  23. // If option is not in alloptions, it is not autoloaded and thus has a timeout 
  24. $alloptions = wp_load_alloptions(); 
  25. if ( !isset( $alloptions[$transient_option] ) ) { 
  26. $transient_timeout = '_transient_timeout_' . $transient; 
  27. $timeout = get_option( $transient_timeout ); 
  28. if ( false !== $timeout && $timeout < time() ) { 
  29. delete_option( $transient_option ); 
  30. delete_option( $transient_timeout ); 
  31. $value = false; 
  32.  
  33. if ( ! isset( $value ) ) 
  34. $value = get_option( $transient_option ); 
  35.  
  36. /** 
  37. * Filters an existing transient's value. 
  38. * The dynamic portion of the hook name, `$transient`, refers to the transient name. 
  39. * @since 2.8.0 
  40. * @since 4.4.0 The `$transient` parameter was added 
  41. * @param mixed $value Value of transient. 
  42. * @param string $transient Transient name. 
  43. */ 
  44. return apply_filters( "transient_{$transient}", $value, $transient );