How to save new transients if query changes?

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 … Read more

Get a list of existing transients

The db query would look like this: SELECT `option_name` AS `name`, `option_value` AS `value` FROM $wpdb->options WHERE `option_name` LIKE ‘%transient_%’ ORDER BY `option_name` To sort the results by their function (site transients, timeouts) use a function like this: add_action( ‘shutdown’, function(){ global $wpdb; $sql = “SELECT `option_name` AS `name`, `option_value` AS `value` FROM $wpdb->options WHERE … Read more

Why are transients cleared prematurely?

TL;DR WordPress part of transient handling is solid, everything is pretty precise Transients use object cache instead of data store for non-default implementations It means that some back-end cache systems get rid of cache that hasn’t been accessed recently Bottom line: it’s not WordPress fault, it only depends on how your back-end cache is set … Read more

Is there any danger in deleting all transients?

For development I would advise to always work with WP_DEBUG set to true and do the following: $key = ‘transient_key’; if( !WP_DEBUG && ( false !== ($transient = get_transient($key)) ){ /* Generate transient manually */ $expiration = 24*60*60;//How long to keep for set_transient($key,$transient, $expiration); } In general – it should be fine deleting transients, as … Read more