How do I cache my WP Query?

Pat Kavanagh
April 23, 2018

Caching is a great way to help improve your site’s page load time. We can achieve a lot of these caching goals through plugins and various server settings, but sometimes you need to get a little more granular for certain pages or features. If you have a large WP Query that is really slowing down a few of your pages, WordPress has some built-in functionality available to help improve those load times. If you take a look at the WordPress Codex page for WP Object Cache, you’ll see their example highlighting just how simple it is:

$result = wp_cache_get( 'my_result' );
if ( false === $result ) {
	$result = $wpdb->get_results( $query );
	wp_cache_set( 'my_result', $result );
// Do something with $result;

We have implemented this on some trouble pages in the past and really seen a jump in performance, so try it out and see how much time you can shave off your page load

Solutions Architecture

browse through our blog articles

Blog Archive