0

I am using wordpress REST api to provide certain data from website to app server. This custom route is used to send default image and everything works fine. Now I want to use set_transient, I used following code to do so.

    $transient='apidata_json_cache';
    $expiration =2*60; // 2 Minutes

    if(false === ($feed=get_transient($transient))) {
        echo '<!--Fresh data-->';

        /*data extraction process here, which is than stored in $feed*/

        set_transient($transient,$feed,$expiration);  
    }

Now each time run the code. The transient is stored with name "_transient__default_thumbnail", _default_thumbnail is the name of one of the ACF field used during extraction of data.

$images['_default_thumbnail'] = get_field('_default_thumbnail','options');

I dont want to save transient with that name. Can you please help to find out what is wrong or what am I missing while creating transient.

Thank you

1 Answer 1

0

It looks you're using different transient names in get_ and set_.

Try the following:

$transient_key = 'apidata_json_cache';
$expiration = 2*60; // 2 Minutes

if( false === ( $feed = get_transient( $transient_key ) ) ) {
    echo '<!--Fresh data-->';

    /*data extraction process here, which is than stored in $feed*/

    set_transient( $transient_key, $feed, $expiration );  
}
1
  • Thanks for pointing it out, my original code has same transient name for both set and get transient. I have edited the question. I don't know what is wrong with this code. Looks like ACF and set_transient are having some sort of cross connection.
    – SD433
    Commented Jul 13, 2017 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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