Set Transient expiration

I have a page that displays a random post every day. In order to change post every 24 hours I use set_transient(‘totd_trans_post_id’, $totd[0]->ID, (60*60*24)); What I’m wondering is this: Does the countdown (60*60*24) start as soon as I have inserted and saved the code? If yes: What happens if I let the code run for … Read more

How to delete transients written by fetch_feed()?

I’m using fetch_feed() to cache external rss sources displayed in a widget. in case the widget (or, more likely, the whole plugin) is deleted/deactivated, i want to manually delete all related transients. In class-feed.php $filename is passed to the constructor of WP_Feed_Cache_Transient{}, which obviously handles the transients for fetch_feed. I just havent figured out how … Read more

How to purge all transient caches?

Is there an easy way to delete all transient caches? A plugin maybe? Or like in drupal “drush cc all”? 3 Answers 3 Not tested, but if you need a quick and dirty way, you could put a script like this in your WordPress folder and call it each time: define( ‘WP_USE_THEMES’, false ); require(‘wp-blog-header.php’); … Read more

Must I serialize/sanitize/escape array data before using set_transient?

Everything is in the question. For a notices system to show warnings/errors in the admin, I´m using transient. When I published my first plugin, I received an email to ask me to sanitize/validate/escape data which inserts in database so… I´m doing a function to wrap set_transient() to do this but I´m not sure if in … Read more

How to use transients and variables

I am trying to implement transient fragments, I’ve been doing what is suggested here: http://css-tricks.com/wordpress-fragment-caching-revisited/ While it is working for headers, footers, landing pages, I am having issues making it work for those sections that include variables. This is my code in functions.php: function fragment_cache($key, $ttl, $function) { if ( is_user_logged_in() ) { call_user_func($function); return; … Read more

Reset Transient on New Day

I have a plugin that interfaces with an API and am storing retrieved schedule data in a transient. Storing the transient for 24 hours: set_transient($schedule_cache, $schedule_data, 60 * 60 * 24); The problem (I think) is: Which 24 hours is it being stored for? I want TODAY to be displayed, but if the transient was … Read more

What to use , set_transient, set_option or file system? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago. Improve this question I have a shortcode that can parse page contents. For example you give it a link … Read more