WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following transient, but if the user changes the value of $url the transient should not be used. I want to know what is the most appropriate way to use this variable with the transient. Should I save the value of $url with Options API to compare it with the new value?

if ( false === ( $videos_result = get_transient( 'html' ) )){
    //HTTP API
    $videos_result = wp_remote_get( $url );

    $response_code = wp_remote_retrieve_response_code( $videos_result );
    $response_message = wp_remote_retrieve_response_message( $videos_result );
    set_transient('html', $videos_result, HOUR_IN_SECONDS );
} else{
    $response_code = 200;
share|improve this question

You could use a sanitized version of the URL as part of the name of the transient … but transient names are limited in their size.

I would store the transient as an array with the URL and the HTML as two parts. Then check if the URL is the same. If it is, use the HTML, else update the transient. Do not save two depended values in different places; this leads to unnecessary synchronization problems.

share|improve this answer

Your Answer


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.