Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [transient]

The Transients API provides a standardized way to store data temporarily (with an expiration time) in the database.

1
vote
2answers
22 views

Only a part of array is stored in transient – what could be causing this?

I have created an autosuggest array that I want to store in a transient. My code looks like this: <?php // Get any existing copy of our transient data $suggest = get_transient('suggest'); if ( ...
1
vote
2answers
18 views

how to build (custom) stats for post views, per month

Does anyone know how I could code something to get the most viewed posts per month (without Jetpack), ideally without having to create a new DB table ? Maybe there is a smart way to achieve this only ...
0
votes
1answer
16 views

delete_transient on click inside a widget form

I'd like to use transient for my widget. User can choose for how long data can be cached (1, 2, 10 hours). I also want to add a button Refresh now inside a widget form. I don't know how to call ...
1
vote
1answer
27 views

Set Transient does nothing

I'm trying to set a transient on my custom query, but it does not seem to work. Every time I refresh the page it still show me different posts each time. After reading up on the transients api, I ...
0
votes
1answer
52 views

Button to clear transients

I would like to add a button on the admin page to clear the transients I use. See my code below: <?php // If this file is called directly, abort. defined('ABSPATH') or exit(); /* * Generate the ...
0
votes
1answer
16 views

Search transients through widget

I have a certain amount of data stored in a transient through a custom developed plugin ( just for this one website ). The transient contains one big array of data that I get from an external API. The ...
0
votes
1answer
29 views

Set user status to absent on Wordpress

Analyzing the function give to get an idea how to solve the question, I do not know if it would work but what if the function give two checks. Let's say the function first checks in the first 3 ...
1
vote
0answers
136 views

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/...
7
votes
1answer
428 views

How to make sure that only one wp_cron() runs at a time?

I have around 20 wp_cron() functions like the following code. Almost all crons run hourly; a few are daily. if ( ! wp_next_scheduled( 'my_task_hook' ) ) { wp_schedule_event( time(), 'hourly', '...
0
votes
1answer
49 views

Set_Transient to end at midnight

I want to set a transient, but that transient to expire at midnight. How can I calculate the time until midnight in PHP for use in that transient definition?
0
votes
3answers
28 views

Using transients to store form notifications

I'm thinking using transients to store form messages to be showed after a form was submited and the page reload. My question is: if two or more user are using the same form in differents sessions, ...
6
votes
2answers
51 views

What's the case against transient-ing almost everything that's mostly static?

Assume I have a menu that's simply static, for most sites, or rather, let's use my example, a blogging site, it almost never, never changes. Why not hook it to a transient that never expires unless ...
1
vote
0answers
22 views

Store a default value for a transient on plugin activation

I'm creating a plugin which is dependent on an external API. And i have to make about a 1000 HTTP requests to the API in order to get a lot of data. And there has to be a 1 second delay between the ...
1
vote
1answer
36 views

transient or not transient

I have a wind captor connected to a dedicated database. Datas from the captor are pushed to the db every minutes. I have no problem to connect to the second db and print the data to a wp page using ...
1
vote
1answer
40 views

How to use transient in this code for related post?

How can I use transient in this code for related post? $related = get_posts(array( 'author' => $author_id, 'category__in' => wp_get_post_categories($post->ID), 'numberposts' =>...
0
votes
1answer
58 views

What is the best practice to set and update Transient value of API data in every minute?

In one of my site, i am using the SERVER cron to get the data from the third party API vai CURL every minute and run the set transient function. It is working fine most of the fine. But when there are ...
0
votes
2answers
84 views

Synchronize Data every minute with set_transient

I synchronize some data of my plugin with an extern API. This synchronize-process should fire every minute. So I use the following code to do that: if ( ! get_transient( 'my_task_sync_method' ) ) { ...
1
vote
1answer
930 views

Force Plugin Updates: “Update Failed: Plugin update failed.” after update one plugin

I'm developing a plugin that needs to do some force update checks for other plugins that I host on my site with EDD, so I had this UI: And when the user clicks on the Update button, it does an API ...
1
vote
1answer
163 views

How do I reset a transient when updating a widget's value?

I have an Instagram widget uses an instagram-scrapper that caches its data in a transient to display photos, based on an username input from the Customizer. Unfortunately, when I update my username, ...
9
votes
2answers
833 views

Is get_option() faster than accessing get_transient()?

Today I run a test over my db to explore the speed difference between accessing a key from options, custom table & transients. I ran the test for 1000 times and following is the time taken to run ...
1
vote
0answers
42 views

Is using custom table to suit business needs instead of transients a big hit to page load speed?

I am working on changing the caching strategy to save the response of an API(which refreshes data in every 30 minutes). Among other things, I came across transients and their unreliable nature of ...
0
votes
1answer
239 views

Custom Plugin Options Won't Update

We wrote a small custom plugin for a client to pull some custom options (set in the WP dashboard) to be used to calculate custom shipping costs in Woocommerce. The issue right now is that changes to ...
1
vote
2answers
128 views

Store sticky post's ids in a transient

I'm developing a theme that has a featured posts section before the main loop of posts. Cool and fresh, right?:) All sticky posts with a featured image in place must be displayed in that section and ...
1
vote
1answer
115 views

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

I have a shortcode that can parse page contents. For example you give it a link to a GitHub md file , it reads it and saves the page content for you. $parse_atts = array( 'id' => $id, ...
4
votes
2answers
439 views

Wordpress transients for a shortcode

I have a small shortcode which basically takes data from a JSON file and displays it on a page. The data in JSON is updated weekly, how can I use a transient so the data for the current week is cached?...
0
votes
2answers
64 views

Is it possible to restore an expired transient?

I have few transient options in my plugin with an expiry time of 45 minutes. After that, they hit an API to get the response. Now in some cases, the server throws an exception or throttles the user in ...
1
vote
1answer
245 views

Clearing cached plugin data if it is using an external object cache

I have created a plugin that caches some of the data it uses - mainly Salesforce REST API call results, and expires them at intervals (by default every 24 hours). The plugin calls these methods to ...
1
vote
1answer
144 views

Storing product price data in the database

I am writing a Wordpress plugin to store product data that is pulled from the Amazon Affiliates API. My goal is to have an admin page where I can add new products and view/edit/remove existing ...
0
votes
1answer
43 views

Set transient name

I am using wordpress REST api to provide certain data from website to app server. This custom route is used to send default image and everything works fine. Now I want to use set_transient, I used ...
1
vote
1answer
156 views

Delete a Wordpress transient from a shortcode on Page/Post update

I hope somebody can help me. I need to delete a transient for all shortcodes located on a post/page when that page is updated. So, the page update should delete the transient just for the shortcodes ...
2
votes
1answer
447 views

Use Transient API to cache queries for all posts in all categories?

I use this to display all posts in all categories. $args_cat = array( // order by category name ascending 'orderby' => 'name', 'order' => 'ASC', // get only top level categories ...
0
votes
1answer
37 views

Transient not working for external data

I am trying to make use of transients in order to load some data I am fetching from another website quicker but the data is not displaying at the moment. Code Below: <div class="col-sm-3 news-...
1
vote
1answer
107 views

Transient feeds and caching error

On our production and staging servers, we're seeing the "WordPress News" feed show an error: After poking around in the WP codebase a bit, I've discovered that this is stored in the wp_options table ...
0
votes
2answers
487 views

How to write update query in WordPress to expire transients

I want to write update query to expire transients . I will upadte their time to 1 in wordpress option table. My query for update is $wpdb->update( 'options', array( '...
0
votes
1answer
36 views

Hi , i am trying to set the post for 24 hours and with it will be changed

Sample Code $args = [ 'posts_per_page' => 1, 'orderby' => 'rand', 'post_type' => 'post', 'ignore_sticky_posts' => true, ]; $r= new WP_Query( ...
1
vote
1answer
67 views

Transient not behaving as expected

I am setting up some transients to reduce load with multiple custom WP_Query objects. When I set the transient to expire within an hour for example, any change to a post / custom post is instantly ...
2
votes
2answers
90 views

Can Transients be used to store sensitive data?

Can I use WordPress Transients to store 'sensitive' data? For example login tokens or Captcha answers? As far as I know all themes and plugins have access to transients. What would be another good ...
1
vote
1answer
55 views

Transient loop issue

I have the following which works fine but only cache first value for first post and doesn't store data for all movie posts in database. How I can solve this problem? I have also a live perview of this ...
0
votes
1answer
570 views

wp_transients / wp_object_cache Vs. using SESSIONS & Cookies : What Should I Use?

My plugin requires me to save query data for some time. The data isn't big as such; just a couple of search parameters entered by the user so that I can use them across pagination. I've figured out ...
1
vote
2answers
554 views

how to get the value of time left for a transient

I am setting up a transient with one hour expiry time. Now i want to know how much time left for the transient to expire. I am getting the transient timeout value with get_option function. Can ...
0
votes
1answer
104 views

Using transient for dynamic css , how to name it?

I am thinking on using transient for my theme dynamic css in order to lower the site load. Currently I have 15 php functions summed up in one collection function that do something like $css .= $...
1
vote
1answer
465 views

How to clear Transients on all sites in Multi Sites environment

I know we have the following command available in WP-CLI to remove transients # Delete all transients $ wp transient delete-all However, my question is does it remove transients on all sites over ...
0
votes
1answer
358 views

Can set_transient() be used in multi-site?

I understand that Transients API is used to cache data and should be intended to store data that is expected to expire. However, please clarify the following. Can set_transient() be used to store ...
1
vote
1answer
2k views

How to store or cache custom shopping cart data for every user's session

I'm developing a shopping cart and I don't want to use any plugins as none of them can serve my needs. So I'm heading to create my own shopping cart. My question is: How to store what the user added ...
0
votes
1answer
282 views

Reset all transients on post or page save

How can I set WordPress to delete transients when a post or a page has been updated or published?
0
votes
1answer
76 views

How to use a transient inside WP_User_Query

Source: How to check if a user (not current user) is logged in? I'm using a transient that's created when users login. $logged_in_users = get_transient('users_online'); Now i'd like to create an ...
7
votes
1answer
537 views

Why are transients cleared prematurely?

You would think that a transient set to expire at a certain time, would exist until that time. Unfortunately it seems they are disappearing from the database earlier, both on test and production. As ...
1
vote
1answer
430 views

Transients are not expiring as expected in simple custom plugin

I have developed a simple shortcode plugin that essentially gets txt files from the url provided in the shortcode and parses a specific piece of data from them (date the file was last modified). I am ...
3
votes
1answer
115 views

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); ...
1
vote
2answers
1k views

Delete transients in website

We have so many error happen on website (WordPress and Woocommerce) error log and it will show the following error message WordPress database error Deadlock found when trying to get lock; try ...