Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does anyone know if there is a Wordpress function to get the timeout value of a saved transient? I am using a transient with a 5 minute timeout to cache data from a web API call locally. Between transient timeouts I load the data locally from the transient acting as a cache and secondary API throttle. What I would like to do is read and display the timeout value of the currently saved transient data so the user knows how long they need to wait before the next data refresh. The value is stored in the 'wp_options' table as '_transient_timeout_transient-name', so I assume I could use the global $wpdb object and just do a SQL query, but I wanted to make sure there wasn't a more elegant way.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

So, after one minute of more thinking, there is an easy solution, although i did not try it myself:

$transient = '_transient_timeout_' . $_your_transient_name;
$transient_timeout = get_option ( $transient );

you should be ready to go with this.

Another Way throught the database would be:

$transient = '_transient_timeout_' . $_your_transient_name;

global $wpdb;

$query = 'SELECT option_value FROM ' . $wpdb->prefix . 'options WHERE option_name = ' . $transient;

$transient_timeout = $wpdb->get_var( $wpdb->prepare( $query ) );

the returned value is a timestamp, but i'm sure you know how to handle it from here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.