Discover in this tutorial how to disable the WP_Term_Query
cache that WordPress incorporates from version 6.4 onwards, using code.
One of WordPress 6.4 new features is that it incorporates the WP_Term_Query
cache. This provides a performance improvement, which is great because it will improve web speed in many circumstances.
As previously done with:
But if you are in a testing/development environment you most likely 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 resolve a problem that may be related to WP_Term_Query
on a production site.
In that case, you need to disable WP_Term_Query
cache.
The good thing is that you can do it using a WordPress hook. Here’s how:
Snippet to disable WP_Term_Query cache in WordPress
Add the following code snippet to your functionality plugin:
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 the results of the WP_Term_Query
query should not be cached. It will be applied to all queries on the web.
If you don’t want it to affect the whole website, another option is to add a parameter inside 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 saved cached.
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 site.
Conclusions
The new feature of caching WP_Term_Query
queries 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? Let me know 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. 😉