Revision: 44741
Updated Code
at April 17, 2011 01:39 by prwhitehead
Updated Code
/**
* Usage: Rename the function and add your own $sql
*/
function test_function(){
global $wpdb;
//check if there is some past cached results
$result = wp_cache_get(date('Y-m-d'), __FUNCTION__);
//if there wasn't a cached result, run your query
if($result === false)
{
//place your SQL here
$sql = "SELECT p.post_author
FROM $wpdb->posts p
WHERE p.post_status = 'publish'
AND p.post_type = 'business' ";
$result = $wpdb->get_col($sql);
//once the query has been run, cache the results
wp_cache_add(date('Y-m-d'), $result, __FUNCTION__);
}
return $result;
}
Revision: 44740
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 17, 2011 01:35 by prwhitehead
Initial Code
/**
* Usage: Rename the function and add your own $sql to the function
*
*
*/
function test_function(){
global $wpdb;
//check if there is some past cached results
$result = wp_cache_get(date('Y-m-d'), __FUNCTION__);
//if there wasn't a cached result, run your query
if($result === false)
{
//place your SQL here
$sql = "SELECT p.post_author
FROM $wpdb->posts p
WHERE p.post_status = 'publish'
AND p.post_type = 'business' ";
$result = $wpdb->get_col($sql);
//once the query has been run, cache the results
wp_cache_add(date('Y-m-d'), $result, __FUNCTION__);
}
return $result;
}
Initial URL
Initial Description
Cache the results of your wordpress database queries for faster page generation
Initial Title
Wordpress: Cache your $wpdb queries
Initial Tags
wordpress, cache
Initial Language
PHP