So I don’t know why the return $cached_result; in the else, but if that’s intentional, then you should 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 was a mistake, then this part:
<?php else: ?>
<?php return $cached_result; ?>
<?php endif; ?>
Should be written as:
<?php else: ?>
<?php $array = json_decode( $cached_result, true ); ?>
<?php endif; ?>
Related Posts:
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- Uploading media with the REST API
- cURL 28 error after switch from to brew php 7.2 on localhost
- Nginx FastCGI_Cache Vs PHP Caching
- Creating a post with the REST API, curl and oauth returning 401 error
- How to make sure that only one wp_cron() runs at a time?
- get_transient(), PHP switch(), and comparison operators
- How to clear WordPress Cache from Server/FTP/Remote location
- Use wp_remote_get to get JSON instagram feed from public profile
- how to get the value of time left for a transient
- PHP Code stuck in Cache [Memcached] [closed]
- Web scraping using transients
- Creating login session via CURL
- WordPress with php 5.5 and zend opcache
- How to use transient in this code for related post?
- Where Does WordPress Make cURL Requests? How To Add cURL Option
- Delete a WordPress transient from a shortcode on Page/Post update
- How to enable Zend Optimiser+ with Batcache
- Dynamic Stylesheet loads but doesn’t finish
- How to combine wordpress_logged_in cookies in one cookie?
- export a csv file from the database with a cronjob
- Programmatic Login from 3rd Party site
- Store a default value for a transient on plugin activation
- Passing UTM Parameters To Modify Page In WordPress
- WordPress & Fastcgi proper setup?
- Dynamic content in template
- Running code before object-cache.php runs
- get post content of particular post by url
- WordPress from url get external source title
- Is the wp_enqueue method efficient?
- customize wordpress database error page
- How to send a HTTP Post request using PHP Curl and WordPress
- SOAP Request/Parsing XML From wp_send_json_success
- REST API works in browser and via AJAX but fails via cURL
- cURL error 6 on news area, and also won’t auto update
- Post to WordPress from another Server via PHP
- Accessing an API with jQuery and AJAX
- Make a page (url) not cacheable [closed]
- calling admin-ajax.php from admin-ajax.php
- Client cant see the Updated dynamic content
- How do I disable cache for a certain page?
- Language does not switch while cache is enabled
- Should I use wp_cache in my plugin to make it faster?
- Refresh page after login with litespeed cache
- Contactform7: display results from CURL
- Use WP Cron to Clear a Page Cache?
- Set user status to absent on WordPress
- Using transients to store form notifications
- How save data on user’s client cache
- Force ‘permanent’ post cache of shortcode results
- Fatal Error cannot log into wordpress and website disappeared
- Are WordPress widgets cached?
- RegExp to EXCLUDE strip HTML (FOR SOMME) comments
- Splash pages on a high traffic site
- Transient Loop Not working as expected
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- How can I improve and optimise my wordpress web server for better performance in 2023
- Redirect to non-WordPress version of home page for search results via index.php customization overwritten
- What is different about using admin-ajax.php in an endpoint and just submitting a form from the front end?
- cURL running slow in WordPress
- Trouble Sending Elementor Form Data via cURL in WordPress
- Can’t programmatically log user in php
- Adding wrapper elements in the_date() like in the_title()?
- Plugin Generate Unexpected output during activation
- PHP code for displaying WordPress posts in a static page not working
- WordPress hit memory limit but not from the server
- How to override url params with rewrite rules vars?
- How to show every second user different types of banners?
- Woocommerce – get_items() returns empty array
- Need help with pagination
- get_comments_number() returns 0
- Adding Additional Variables on Menus Page
- Querying for specific tags
- Why the dynamic_sidebar() call is putted into an ul tag?
- Timber right sidebar in WordPress theme
- Build A Custom SQL Query for WordPress Search
- Get main parent category for post (WordPress/Advanced Custom Fields)
- How to run complex query using PHP
- Store ajax data in PHP variable
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Configure WordPress to Use Responsive Image Rendering
- How can i create a function tag in my plugin
- Why the responseText containing those two arrow signs at the beginning
- Call jQuery function from PHP?
- How to Get Linked Elements for a specific ml_source_elementid
- Metabox – Displaying the Value of a Metabox
- Best way to define a database with product codes and back-end support?
- Is there a way to randomize and connect a background and header image?
- Post Thumbnail on Single (if elseif else)
- Display pages from specific page template
- dynamically filter by category via sub-menu
- Sidebar doesnt get updated?
- Edit the Publish Widget Options
- WordPress post pagination on custom template not working
- get_option(‘admin_email’) not working in wordpress when using ajax call
- wordpress featured image
- How do I update product shipping using PHP in WooCommerce?
- How can I edit the WooCommerce Mini DropDown Cart to read as follows
- base64_encode conflict with convert_smilies in wordpress
- Disable Typed Parameters for JavaScript in PhpStorm? [closed]