Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active April 14, 2020 06:32
Show Gist options
  • Save wpscholar/261cd33dd17738cc7075 to your computer and use it in GitHub Desktop.
Save wpscholar/261cd33dd17738cc7075 to your computer and use it in GitHub Desktop.
Example of a cached query
<?php
$cache_key = '%cache_key%';
$query = get_transient( $cache_key );
if ( ! $query ) {
$query = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 12,
'order' => 'ASC',
'orderby' => 'title menu_order',
) );
set_transient( $cache_key, $query, 3600 ); // Expires in 1 hour (60 seconds * 60 minutes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment