get_transient

The timeline below displays how wordpress function get_transient has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filters the value of an existing transient before it is retrieved.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Returning a value other than false from the filter will short-circuit retrieval
     * and return that value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return that value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters("pre_transient_{$transient}", false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache() || wp_installing()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout.
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filters an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters("transient_{$transient}", $value, $transient);
}

WordPress Version: 9.1

/**
 * Retrieves the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filters the value of an existing transient before it is retrieved.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Returning a truthy value from the filter will effectively short-circuit retrieval
     * and return the passed value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return that value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters("pre_transient_{$transient}", false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache() || wp_installing()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout.
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filters an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters("transient_{$transient}", $value, $transient);
}

WordPress Version: 5.5

/**
 * Retrieves the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filters the value of an existing transient before it is retrieved.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Returning a truthy value from the filter will effectively short-circuit retrieval
     * and return the passed value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return that value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters("pre_transient_{$transient}", false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout.
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filters an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters("transient_{$transient}", $value, $transient);
}

WordPress Version: 5.4

/**
 * Retrieves the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filters the value of an existing transient.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return the returned value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters("pre_transient_{$transient}", false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout.
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filters an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters("transient_{$transient}", $value, $transient);
}

WordPress Version: 4.7

/**
 * Get the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filters the value of an existing transient.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return the returned value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters("pre_transient_{$transient}", false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filters an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters("transient_{$transient}", $value, $transient);
}

WordPress Version: 4.6

/**
 * Get the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filters the value of an existing transient.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return the returned value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters('pre_transient_' . $transient, false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filters an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters('transient_' . $transient, $value, $transient);
}

WordPress Version: 4.4

/**
 * Get the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filter the value of an existing transient.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $pre_transient The default value to return if the transient does not exist.
     *                              Any value other than false will short-circuit the retrieval
     *                              of the transient, and return the returned value.
     * @param string $transient     Transient name.
     */
    $pre = apply_filters('pre_transient_' . $transient, false, $transient);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!wp_installing()) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filter an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     * @since 4.4.0 The `$transient` parameter was added
     *
     * @param mixed  $value     Value of transient.
     * @param string $transient Transient name.
     */
    return apply_filters('transient_' . $transient, $value, $transient);
}

WordPress Version: 4.3

/**
 * Get the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filter the value of an existing transient.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     *
     * @param mixed $pre_transient The default value to return if the transient does not exist.
     *                             Any value other than false will short-circuit the retrieval
     *                             of the transient, and return the returned value.
     */
    $pre = apply_filters('pre_transient_' . $transient, false);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!defined('WP_INSTALLING')) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                $timeout = get_option($transient_timeout);
                if (false !== $timeout && $timeout < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filter an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     *
     * @param mixed $value Value of transient.
     */
    return apply_filters('transient_' . $transient, $value);
}

WordPress Version: 4.1

/**
 * Get the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filter the value of an existing transient.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     *
     * @param mixed $pre_transient The default value to return if the transient does not exist.
     *                             Any value other than false will short-circuit the retrieval
     *                             of the transient, and return the returned value.
     */
    $pre = apply_filters('pre_transient_' . $transient, false);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!defined('WP_INSTALLING')) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                if (get_option($transient_timeout) < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filter an existing transient's value.
     *
     * The dynamic portion of the hook name, `$transient`, refers to the transient name.
     *
     * @since 2.8.0
     *
     * @param mixed $value Value of transient.
     */
    return apply_filters('transient_' . $transient, $value);
}

WordPress Version: 4.0

/**
 * Get the value of a transient.
 *
 * If the transient does not exist, does not have a value, or has expired,
 * then the return value will be false.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return mixed Value of transient.
 */
function get_transient($transient)
{
    /**
     * Filter the value of an existing transient.
     *
     * The dynamic portion of the hook name, $transient, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     *
     * @param mixed $pre_transient The default value to return if the transient does not exist.
     *                             Any value other than false will short-circuit the retrieval
     *                             of the transient, and return the returned value.
     */
    $pre = apply_filters('pre_transient_' . $transient, false);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!defined('WP_INSTALLING')) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                if (get_option($transient_timeout) < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filter an existing transient's value.
     *
     * The dynamic portion of the hook name, $transient, refers to the transient name.
     *
     * @since 2.8.0
     *
     * @param mixed $value Value of transient.
     */
    return apply_filters('transient_' . $transient, $value);
}

WordPress Version: 3.9

/**
 * 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.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped
 * @return mixed Value of transient
 */
function get_transient($transient)
{
    /**
     * Filter the value of an existing transient.
     *
     * The dynamic portion of the hook name, $transient, refers to the transient name.
     *
     * Passing a truthy value to the filter will effectively short-circuit retrieval
     * of the transient, returning the passed value instead.
     *
     * @since 2.8.0
     *
     * @param mixed $pre_transient The default value to return if the transient does not exist.
     *                             Any value other than false will short-circuit the retrieval
     *                             of the transient, and return the returned value.
     */
    $pre = apply_filters('pre_transient_' . $transient, false);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!defined('WP_INSTALLING')) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                if (get_option($transient_timeout) < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    /**
     * Filter an existing transient's value.
     *
     * The dynamic portion of the hook name, $transient, refers to the transient name.
     *
     * @since 2.8.0
     *
     * @param mixed $value Value of transient.
     */
    return apply_filters('transient_' . $transient, $value);
}

WordPress Version: 3.7

/**
 * 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.
 *
 * @uses apply_filters() Calls 'pre_transient_$transient' hook before checking the transient.
 * 	Any value other than false will "short-circuit" the retrieval of the transient
 *	and return the returned value.
 * @uses apply_filters() Calls 'transient_$option' hook, after checking the transient, with
 * 	the transient value.
 *
 * @since 2.8.0
 * @package WordPress
 * @subpackage Transient
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped
 * @return mixed Value of transient
 */
function get_transient($transient)
{
    $pre = apply_filters('pre_transient_' . $transient, false);
    if (false !== $pre) {
        return $pre;
    }
    if (wp_using_ext_object_cache()) {
        $value = wp_cache_get($transient, 'transient');
    } else {
        $transient_option = '_transient_' . $transient;
        if (!defined('WP_INSTALLING')) {
            // If option is not in alloptions, it is not autoloaded and thus has a timeout
            $alloptions = wp_load_alloptions();
            if (!isset($alloptions[$transient_option])) {
                $transient_timeout = '_transient_timeout_' . $transient;
                if (get_option($transient_timeout) < time()) {
                    delete_option($transient_option);
                    delete_option($transient_timeout);
                    $value = false;
                }
            }
        }
        if (!isset($value)) {
            $value = get_option($transient_option);
        }
    }
    return apply_filters('transient_' . $transient, $value);
}