Last active
April 14, 2020 06:32
-
-
Save wpscholar/261cd33dd17738cc7075 to your computer and use it in GitHub Desktop.
Example of a cached query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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