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.6k
22 votes
Accepted

Is get_option() faster than accessing get_transient()?

The TLDR: For 99% of people they're the same thing and just as fast as each other. This is micro-optimisation and not worth your time. Today I run a test over my db to explore the speed difference ...
Tom J Nowell's user avatar
  • 59.2k
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
  • 46.1k
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
  • 59.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
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,583
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.5k
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.4k
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

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.4k
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.4k
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,081
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
4 votes
Accepted

Will cron job run if page loaded is being served from cache?

It depends on the plugin and the cache method you are using. For example, as far as I remember, WP Super Cache offers two different cache methods: PHP Cache HTML Cache Using the first method creates ...
Johansson's user avatar
  • 15.3k
4 votes

How to stop WP API endpoint from caching?

If you have access to your request header you can add the line. Cache-Control: private or Cache-Control: no-cache. This will force well-behaved hosts to send you fresh results.
SungamR's user avatar
  • 41
4 votes
Accepted

Wordpress REST API, Expired Nonce from Cache results in 403 forbidden

Based on the authentication documentation here - a nonce key needs to be passed with each request. So if the nonce key is being cached on the frontend beyond its lifespan, you will need to hook ...
thomas_jones's user avatar
3 votes

Local PC cache stays filled with old WordPress Site data

Unsurprisingly so since you tell browser to cache everything for 1 month by default (ExpiresDefault "access plus 1 month"). You should limit long caching times to static resources and leave pages ...
Rarst's user avatar
  • 99.7k
3 votes

Files cached as CSS or PHP?

A great deal of this will depend on your server configuration, but: Will WP Super Cache cache the css.php output? Extremely unlikely. If your file simply generates CSS from a few variables, then no. ...
Tom J Nowell's user avatar
  • 59.2k
3 votes

How do you avoid caching during development?

What worked for me running Wordpress on a Bitnami stack under Windows was to edit my php.ini file and restart my server. In the [opcache] section change the opcache.revalidate_freq to 1 opcache....
Steve B's user avatar
  • 31
3 votes
Accepted

Nonces and Cache

I know this question is ancient, but no, it's not very secure. Anyone with knowledge of the AJAX endpoint would be able to generate valid nonces, which defeats the purpose in the first place. That ...
DarkNeuron's user avatar

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