Skip to content

Instantly share code, notes, and snippets.

@zeropointdevelopment
Created December 27, 2013 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeropointdevelopment/8141457 to your computer and use it in GitHub Desktop.
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/
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