According to code in OP, the only thing that changes the result is the $tags
variable.
In this case, the easiste way to do the trick is make the $tags
part of the transient name.
function get_posts_by_tags($tags){
$transient="rest-posts-" . md5(serialize($tags));
if(false === ($result = get_transient($transient))) {
// the rest of yout function here ...
if (!is_wp_error($data)){
$result = json_decode( $data );
set_transient($transient, $result, 24 * HOUR_IN_SECONDS);
}
}
return $result;
}
So for every $tags
there is a transient.
If different pages result in same $tags
they will query (and store) same transient and everything should work as expected.
Related Posts:
- When should I be using the Transients API?
- Cache remote (HTTP) request with Transients API
- Is there any danger in deleting all transients?
- Why are transients cleared prematurely?
- Get a list of existing transients
- Storing posts social counters by using transient api
- Integrating WP-TLC-Transients with WordPress – Where to Begin?
- Is priming a Transient Cache possible?
- What causes a transient to changes status to “Does Not Expire”?
- Reset Transient on New Day
- How to use transients and variables
- Transient storage location? database/xcache/w3Total Cache?
- How to delete transients written by fetch_feed()?
- Set Transient expiration
- WordPress transient doesn’t use the transient
- How do I reset a transient when updating a widget’s value?
- How to clear Transients on all sites in Multi Sites environment
- Is this the proper usage of creating / using a transient?
- Should I use the Transients API to temporarily hold edited attachements?
- transient or not transient
- Can Transients be used to store sensitive data?
- wp_options flooded with transient API entires
- Why Transients may not work correctly?
- How many transients is too many transients
- Synchronize Data every minute with set_transient
- Difference between get_site_transient() and get_transient()
- delete_transient on click inside a widget form
- Set_Transient to end at midnight
- Whats wrong with this transient? Not caching as expected
- Set transient with get posts error
- Clear Transients
- Unique Transients user id for Non-Logged In users
- Transient is never set. Why?
- Button to clear transients
- Set transient name
- Hacked site using transient API?
- Ajax call to transients
- Why can’t I save encrypted data in a transient?
- Doesn’t set_transient() add multiple rows with the same key?
- Should I use Transient API to store HTML String, or Object?
- Show popular post in another php website via WP REST JSON API
- How do I cache (core) API requests?
- Best practices for using the transients API
- Are transients private or public?
- Using transients in conjunction with memcached
- Does using set_transient() function can lead to MySQL problems?
- How to update/insert custom field(post meta) data with wordpress REST API?
- How to loop through JSON data in wordpress WP REST API
- How to purge all transient caches?
- Should the caching of WordPress menus be specific to each page?
- Long option names fail silently?
- Add media with WP-Rest-API v2 II
- pre_set_site_transient_update_plugins wont call on hosted webspace
- wordpress custom endpoint multiple params
- Must I serialize/sanitize/escape array data before using set_transient?
- WP-API and Basic Auth returning 403 on POST but not GET
- WordPress API returns empty page when page is less than X-WP-TotalPages
- How to filter users on custom meta fields in WP JSON v2?
- WP API to fetch all records for /posts, /media, /categories
- How to purge all transient caches?
- How to retrieve custom meta term of category taxonomy from WP Rest API?
- Gutenberg Custom Block Getting All Posts
- Get all tags not just first 10 with wp api 2.0
- Mass importing json data into custom fields (postmeta)
- Transient API and caching Plugins
- How to cache posts based on $_GET? Option name is too long? Options / transients
- WP REST API V2 – Add user data to response
- How to quickly reorder posts in the admin panel that will persist for the wp-api
- Set Transient does nothing
- Storing product price data in the database
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- get_post_type_object() does not work with switch_to_blog()
- is it possible to filter a rest api endpoint by using a registered rest field?
- WordPress API for search
- Update a post based on results from GET request to another server
- WP Rest get all by post within that category, by category name not by cat ID
- OAuth1 empty “authentication” in /wp-json
- WP API: Get posts excluding those with a tag or category name
- How to replace a function using a child theme?
- How can I list all installed plugins/themes/versions from CLI/API?
- Why does get_transient() always return string even if integer set?
- Media gallery images url instead of ID on WP API Response
- What is the best way (regarding performance) to set transients for logged in users?
- How to create WordPress custom end point with multiple parameters?
- Is there a better way to access transients using javascript
- Cant create or update meta fields using WordPress REST API
- Storing transients giving database error
- WordPress REST API – get custom taxonomy category posts
- Save large WP_Query to transient === false
- Woocommerce – how to round up all prices to end in .99
- Remove unwanted fields from WP API response
- How to add a post’s view count into the WordPress API response
- wordpress api make 2 custom post type with single request
- Consume legacy rest api dependent upon WP API plugin
- Hiding WordPress REST endpoints from public viewing using Basic Authentication
- What is the best way to upload a temporary & sensitive file and then delete it when done
- Transient Loop Not working as expected
- What is the best way to cache pages and queries in WordPress?
- How can I use React packages with the clasic editor?
- How can i store cache of wordpress a database request without plugins?