Discover in this tutorial how to disable the WP_User_Query
cache that WordPress incorporates from version 6.3, using code.
One of the new features of WordPress 6.3 is that it incorporates the WP_User_Query
cache. This provides a performance improvement, which is great because it will improve web speed in many circumstances.
But if you are in a testing/development environment you probably don’t want this cache to apply as it can mask the changes you are making.
Another circumstance where it may be worth avoiding the cache is when you are trying to solve a problem that may be related to WP_User_Query
on a production website.
In that case, you need to disable the WP_User_Query
cache.
The good thing is that you can do it using a WordPress hook. Here’s how:
Snippet to disable WP_User_Query cache in WordPress
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case you use the pre_get_users
hook to indicate that WP_User_Query
query results should not be cached. It will apply to all queries on the site.
If you don’t want it to affect the entire website, another option is to add a parameter within the query itself. This would be an example:
To see this and another 1097 code snippets of this website, login or subscribe here.
By setting the cache_results
parameter to false
you get that query is not cached saved.
I reiterate that I only recommend you to do this in a test environment or apply it temporarily to solve a problem in a development website.
Conclusions
The new feature of WP_User_Query
cache is great because it substantially improves web performance.
But if you are in a testing environment or doing some debugging you may want to disable it, and now you know how.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉