Created
December 27, 2013 02:01
-
-
Save zeropointdevelopment/8141457 to your computer and use it in GitHub Desktop.
[WordPress] Code from our blog post - Using WordPress Transients to Reduce Database Load http://www.limecanvas.com/using-wordpress-transients-reduce-database-load/
This file contains 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
global $wpdb; | |
$transient_name = 'lc-latest-10-posts'; | |
$post_ids = get_transient( $transient_name ); | |
if ( $post_ids == FALSE ){ | |
$sql = "SELECT post.ID | |
FROM $wpdb->posts post | |
WHERE | |
post.post_type = 'post' | |
AND post.post_status = 'publish' | |
ORDER BY post.post_date | |
DESC | |
LIMIT 0,10"; | |
$results = $wpdb->get_col( $sql ); | |
if( $results ){ | |
foreach ( $results as $result ){ | |
$post_ids[] = $result; | |
} | |
set_transient( $transient_name, $post_ids, 60 * 60 * 6 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment