Hot answers tagged

56 votes
Accepted

Explanation of update_post_(meta/term)_cache

Object cache everywhere WordPress tries to reduce the number of database queries as much as possible. For example, anytime you get a meta field or a taxonomy field, before querying the database, ...
gmazzap's user avatar
  • 45.9k
29 votes
Accepted

Getting failure when using filemtime() with wp_enqueue_style

It's because you're retrieving it via URL, but filemtime() requires a path. Use get_stylesheet_directory() instead. That returns a path: function pro_styles() { wp_enqueue_style( 'child-style', ...
Jacob Peattie's user avatar
22 votes

Any reason why wp_cache_set not to work?

As of WordPress 6.3, both WP_Query and WP_User_Query automatically cache requests. The original question example is outdated since get_posts() uses WP_Query. The wp_cache_*() functions are non-...
Howdy_McGee's user avatar
  • 20.5k
19 votes
Accepted

Should I use Transient API to store HTML String, or Object?

Should I use Transient API at all here? No. In a stock WordPress install transients are stored in the wp_options table, and only cleaned up during core upgrades. Suppose you have 50,000 posts, that'...
kovshenin's user avatar
  • 2,573
19 votes
Accepted

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 ...
Tom J Nowell's user avatar
  • 58.2k
12 votes

Should I use Transient API to store HTML String, or Object?

Not All WP Code Is Public Code If you are going to release something public, then all the things kovshenin said are perfectly valid. Things are different if you are going to write private code for ...
gmazzap's user avatar
  • 45.9k
12 votes
Accepted

How to cache bust a child theme style.css

@dalbaeb's comment eventually lead to insightful discussions and a feasible solution. Thanks a lot! I believe the reason my child theme CSS was loaded using 'ver=<parent-theme-version> was ...
Marcel Stör's user avatar
12 votes
Accepted

Is it possible to completely stop WP_Query retrieving posts?

At the moment, it is not possible. When 'pre_get_posts' runs, is too late to stop WP_Query to perform a query. WordPress itself, when you try to query a taxonomy that does not exists, adds AND (0 = ...
gmazzap's user avatar
  • 45.9k
11 votes
Accepted

How can I clear oEmbed caches for YouTube on posts as they are loaded

How to trigger an oembed cache regeneration The default cache time is 24 hours and we can adjust it with the oembed_ttl filter. But as you've noticed, expired cache is not enough to trigger a cache ...
birgire's user avatar
  • 66.7k
10 votes
Accepted

Using get_posts vs. WP_Query

Edit: WP Core has changed since the question and answer were written. While I still believe it's better to use WP_Query for other reasons, the suppress_filters rule should be gone from WPCS/VIPCS now ...
Tom J Nowell's user avatar
  • 58.2k
9 votes

Forcing reload of editor-style.css

I couldn't get toscho's answer to work for the current version of WordPress (4.7.2), and that seems to be because the TinyMCE init array has a cache_suffix set to 'wp-mce-' . $tinymce_version. So ...
icecold_3000's user avatar
8 votes
Accepted

Is define('WP_CACHE', true) needed for object caching?

No, including this constant with a value of true loads advanced-cache.php. Object-cache.php is loaded and used automatically. See https://wordpress.org/support/article/editing-wp-config-php/
Ihor Vorotnov's user avatar
7 votes
Accepted

wp_cache_set() or wp_cache_add()

According with WP Object API documentation both functions accepts these arguments: $key: the key to indicate the value. $data: the value you want to store. $group: (optional) this is a way of ...
cybmeta's user avatar
  • 20.3k
6 votes

How can I cache WordPress Rest API Response

You should create a new instance from WP_REST_Response to set the Cache-Control value. <?php register_rest_route('wp/v2', '/your_endpoint', array( 'methods' => 'GET', 'callback' => '...
Mostafa Soufi's user avatar
5 votes
Accepted

Nginx FastCGI_Cache Vs PHP Caching

Nginx is really good at concurrency (PHP not so much) so you should try a bit more than 180 requests per second. Maybe 500, or 1000 depending on your server resources and network throughput. The ...
kovshenin's user avatar
  • 2,573
5 votes

Getting "Fatal error: Call to undefined function wp_cache_get() in option.php" after updating a cache plugin

I solved deleting the w3tc cache plugin from ftp
Andrea Capretti's user avatar
5 votes
Accepted

Is there a get_post(s) filter that can alter/replace the output completely?

If you look towards the end of the query process (which starts with the pre_get_posts filter), there is a filter called the_posts (not to be confused with the_post). This allows you to modify the ...
cjbj's user avatar
  • 14.1k
5 votes

Getting failure when using filemtime() with wp_enqueue_style

Just to expand on Jacob Peattie Answer for people that have CSS file in a custom plugin, you can use filemtime( plugin_dir_path(dirname(__FILE__)).'plugin-folder/css-file-path.css' )
Marcin Lentner's user avatar
5 votes

Wordpress transients for a shortcode

I add it the transient name to a variable to handle it easier. Next, I check if the return value from the get_transient is false and update the variable name and the transient. You can try this one: ...
Drupalizeme's user avatar
  • 1,606
5 votes

Is get_option() faster than accessing get_transient()?

If no object caching is found, get_transient calls get_option twice, once or the expiry interval and one for the value, therefor it is not going to be faster. get_option performance by itself will be ...
Mark Kaplun's user avatar
  • 23.2k
5 votes
Accepted

How can I free up the memory used by update_post_meta?

It turns out that it was due to Query Monitor, a plugin that records info about each query. Every time update_post_meta ran, Query Monitor would store some data about the query, which eventually added ...
Pikamander2's user avatar
4 votes

Explanation of update_post_(meta/term)_cache

The main point of interest here is the update_post_caches function. It is called after WP_Query got all the posts from the DB. Usually, the reason you want the posts in the first place is to display ...
Mark Kaplun's user avatar
  • 23.2k
4 votes

Usage of Direct Database Call Without Caching Error

I agree with @Tom J Nowell: I'd suggest you remove it, or better yet just say "all rights reserved". But in the quest for answers, here's a suggestion using an option field to cache the years: /*...
TheDeadMedic's user avatar
  • 36.3k
4 votes

wp_transients | wp_object_cache VS SESSIONS & Cookies?

set_transient() using wp_cache_set() and mysql database. WP Cache API using $GLOBAL(global session for application). Cookies and Session saves data only for one current user(cookies in browser, ...
Igor Sorish's user avatar
4 votes
Accepted

Should i clear the plugin cache for cache busting?

The main obvious problem with your scheme is that when someone wil try to reload an old page it will get all kinds of 404 when requesting the JS and CSS since those files are not on the server anymore....
Mark Kaplun's user avatar
  • 23.2k
4 votes

Automatically Refresh WordPress Stylesheet

"Quick" fix: Right Click -> view page source ( ctrl+U ), find .css file you changed, open it in new tab and reload ( you should see change in place you've made it ) ONLY in development mode add php ...
WP Vlad's user avatar
  • 41
4 votes

Want to enforce the visitor to load the new version of your stylesheets and scripts

Sounds like you are talking about cachebusting. Changing the querystring makes the browser interpret the URL as a new resource. Unless you want to change the entire filename there really isn't a ...
majick's user avatar
  • 5,071
4 votes

Why my browser keeps loading old version of custom JavaScript files in \divi\js?

First get datetime stamp of your js file's last modification, and use it as fourth parameter of wp_enqueue_script function: $path = 'full path to your script file'); $handle = 'your_handle'; $src = '...
Frank P. Walentynowicz's user avatar
4 votes
Accepted

Wordpress transients for a shortcode

Use this instead of the line in wich you define $days (your second line): $transient = get_transient( 'your_transient_key' ); if( !$transient ): $days = file_get_contents( 'json_file' ); ...
GDY's user avatar
  • 428

Only top scored, non community-wiki answers of a minimum length are eligible