Questions tagged [transient]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
26 views

Using `set_transient()` when saving a custom post type

I've got multiple custom post types registered via a plugin and one of them is used as a precursor for multiple other queries. In an attempt to reduce queries throughout the site, I've attempted to ...
0
votes
0answers
18 views

Transient is never set. Why?

In one page, I try to set/get two transients. The second works fine. The first doesn't work at all. I can not figure out why. Here's the relevant code. $lat = round($toReturn["location"][...
0
votes
1answer
45 views

How many transients is too many transients

I am using transients on my Wordpress site, and we may end up with more than 1,000,000 transients in the worst case situation. I think 500,000 is more likely, but I was wondering if having too many ...
0
votes
2answers
18 views

Set WordPress Transient Expiration via Variable Value

I want to set WordPress Transient via Variable Value. This is an example code with what I'm trying to achieve. <?php if ( false === get_transient( 'special_query_results' ) ) { ...
5
votes
1answer
282 views

Do WordPress' cron's clean up expired transients?

WordPress has a cron named "delete_expired_transients" as seen in the image below. In this way, does it clean expired transients daily? Or is it just giving us action? Should we clean it ...
4
votes
1answer
120 views

Why does WordPress create two transients with the same name when I specify timeout value?

Working with transients with a timeout, I seem to be getting two transients created, and I don't quite understand why. Looking at the source code on: https://developer.wordpress.org/reference/...
0
votes
1answer
103 views

Change WooCommerce product and variation prices programatically without affecting performance

I need to set a global 5% discount (or 0.95 margin) for all logged in customers on my store. I've used filters to alter the price for all simple products and product variations. To get it working ...
1
vote
0answers
14 views

Transient Code affecting comments

I am using this code in single posts but it is affecting my comments (changing the comments of the post to the last post appearing in the sequence). Could someone guide me on how to stop this from ...
0
votes
0answers
22 views

Save large WP_Query to transient === false

I try to save a WP_Query to a transient but it's always comes back false dispite the fact that the transient is saved. Here is the code: $fitsToTransientName = 'g_wc_fits_to_' . get_the_ID(); $...
0
votes
1answer
187 views

Woocommerce - how to round up all prices to end in .99

I need to update all prices in my store to end in .99, both on the front end and in the database. I have the following code which appears to do it when I run a shortcode, but I have a problem. When I ...
1
vote
1answer
22 views

WordPress transient doesn't use the transient

I'm new to the transients but I think I get the logic behind it. So I have a blog and I grab the posts via the API from another blog of mine. Now I would like to save the data in a transient so I don'...
0
votes
1answer
344 views

Need help in setting up a transient using API Key and if possible updating it in the ACF field

I am trying to set up a shortcode that will fetch Moz API data but I am facing issues. Sometimes, it returns values to 0, and sometimes it works. I don't know what I am doing wrong here. Might be I ...
4
votes
1answer
328 views

Does using set_transient() function can lead to MySQL problems?

As a plugin author, I have to think about many things. One of my plugins uses a temporarily PHP session to save the JSON data that receives through its API in array type. Because PHP session has its ...
0
votes
1answer
83 views

Check the stored / cached WP_Query with transients on post change

right now I have WP_Query stored for 24h (1day) with set_transient function. Everything works fine like it should. But if for example I change the post which is in the stored array to private or ...
0
votes
1answer
128 views

set_transient fails if the value has more than 60.000 characters

I have a problem which I can't figure out. I have a collection of object which sometimes can be very big. I have to store the entire collection as a serialized transient. The problem is that when the ...
0
votes
1answer
338 views

WordPress transient not working with WP Engine

For some reason, when we we're on another server (Tierpoint) everything worked fine and we recently switched over to WP Engine and the transients that I was using for my module have stopped working. ...
0
votes
1answer
350 views

wp_trash_post() duplicates post to trash

I'd like to move a post to the trash in the loop. Here's my code; function run_every_five_minutes() { global $post; $wp_query = new WP_Query(array('cat' => array(1), 'posts_per_page' => ...
0
votes
1answer
107 views

Using Transients

I am new to the transient concept. But I am not sure about the efficient method to use it. I really liked it as it removed the duplicate queries that I had. I have set set_transient( '...
-1
votes
1answer
177 views

how to use transient method?

It was suggested to use a transient method to remove the duplicate queries Duplicate Queries Why does this don't work? Is it the wrong way to use it private function get_acf_list() { if(!...
0
votes
1answer
70 views

Updating transient value frequently

Is it alright conceptually to update transient value frequently. I am building up a login form & every time user enters invalid credentials, store the incorrect attempts. So I am using user IP ...
1
vote
2answers
220 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
266 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
130 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
558 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
280 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
29 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
52 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 ...
2
votes
1answer
984 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/...
9
votes
1answer
2k 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
238 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
299 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, ...
5
votes
2answers
81 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
31 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
67 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
129 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
149 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
569 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
2k 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
749 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
2k 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
53 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
380 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
309 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 ...
2
votes
1answer
388 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, ...
3
votes
2answers
704 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
99 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
702 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
246 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
63 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
287 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 ...