So I don't know whatwhy the return $cached_result;
here does or why it worked before for youin the else
, but if that's intentional, then you shouldn'tshould probably do:
return json_decode( $cached_result, true );
Because you're caching the response body (which is a JSON string) and you're reading the non-cached result like so: $array = json_decode($result, true);
.
But if that return
therewas a mistake, then this part:
<?php else: ?>
<?php return $cached_result; ?>
<?php endif; ?>
Instead, that shouldShould 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 );
..