Skip to main content
1 of 2
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48

I don't know what the return here does or why it worked before for you, but you shouldn't return there:

<?php else: ?>
    <?php return $cached_result; ?>
<?php endif; ?>

Instead, that should be written as:

<?php else: ?>
    <?php $array = json_decode($cached_result, true); ?>
<?php endif; ?>

Because the code that follows has $array['data']:

<?php
/* Loop through the array and only pull API fields */
$mediaUrls = array_map(function($entry) {
    ...
}, $array['data']);
?>

Additionally, you should read the cached result the same way you read the non-cached result; i.e.:

// Reading the non-cached result.
$array = json_decode($result, true);

// And reading the cached result.
$array = json_decode($cached_result, true);

But if you actually did mean to return the data, then perhaps you should do return json_decode( $cached_result, true ); ..

Sally CJ
  • 39.9k
  • 2
  • 26
  • 48