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?
- What would cause set_transient() and set_site_transient() to fail silently?
- Are transients garbage collected?
- How does object caching work?
- Hiding WordPress REST API v2 endpoints from public viewing
- Get WP Navigation Menu from REST API V2
- Should I use Transient API to store HTML String, or Object?
- Will it break my site if I delete all transient records in wp_options table?
- How do I access the body of a WP API request in a custom route?
- Get post count in wp rest API v2 and get all categories
- Query WP REST API v2 by multiple meta keys
- Is get_option() faster than accessing get_transient()?
- Show popular post in another php website via WP REST JSON API
- Uploading media with the REST API
- WP-API v2 Custom Endpoint Response Formatting
- How do I cache (core) API requests?
- Implementing Isomorphic JavaScript (React JS) in WordPress?
- Best practices for using the transients API
- WP REST API only returning partial list of users
- Are transients private or public?
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- Using transients in conjunction with memcached
- WP API returning SQL results as strings, rather than numbers
- wp-cron.php – How are WP’s Cron transients removed?
- Do WordPress’ cron’s clean up expired transients?
- Using a wildcard with delete_transient()
- Does set_transient() overwrite/update transient option with same key?
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- wp rest api v2 return json_no_route
- What’s the case against transient-ing almost everything that’s mostly static?
- WordPress Rest API
- Retrieving pages with multiple tags using REST API
- Insert variations via woocommerce api [closed]
- Fetching private posts or custom post types via WP-API with basic authentication
- WP-REST API not returning all its endpoints, 404 on documented endpoints
- Custom endpoint and X-WP-TotalPages (headers)
- Does using set_transient() function can lead to MySQL problems?
- WP Rest API v2 filter and display latest post with specific tag
- Fallback when Transient API fails
- Why does WordPress create two transients with the same name when I specify timeout value?
- WordPress Rest API: How do we validate with our custom API key?
- How to delete cached transients from a widget instance properly?
- How to update/insert custom field(post meta) data with wordpress REST API?
- How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?
- Fragment caching increasing database queries
- How to loop through JSON data in wordpress WP REST API
- Should I store external API data in my WP database or keep it as a transient?
- WordPress transients for a shortcode
- WP API V2 returning Invalid User ID
- Unset data in custom post type WordPress API (wp-json)
- Can I list all installed plugins/versions and wp version from API
- How do I retrieve a list of popular plugins using the WordPress.org Plugin API?
- How to purge all transient caches?
- WP API : date_query parameter
- How to filter or search the posts using postmeta tables custom meta fields with wordpress REST API
- WP-API: how do I allow authenticated clients only?
- How to delete a transient on post/page publish?
- Hiding API routes list
- WP REST API V2 – Modifying responses
- WordPress wp-json API – Custom Post Type returns 403
- Should the caching of WordPress menus be specific to each page?
- Long option names fail silently?