/ Published in: PHP

Cache the results of your wordpress database queries for faster page generation
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Usage: Rename the function and add your own $sql */ function test_function(){ global $wpdb; //check if there is some past cached results //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 } return $result; }
Comments
