Advertisement
cw17s0n

transients

Jul 6th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. in functions.php
  2.  
  3. function list_all_agent_posts() {
  4.   // Configuration
  5.     $transName = 'tr-agent-posts'; // Name of value in database.
  6.     $cacheTime = 720; // Time in minutes between updates.
  7.   // Do we already have a saved transient?
  8.     $agent_posts = get_transient($transName);
  9.   // If not, lets get one.
  10.     if($agent_posts === false):
  11.       $agent_posts = new WP_Query(array('post_type' => 'agent', 'order' => 'ASC', 'orderby' => 'title'));
  12.   // Save our new transient.
  13.     set_transient($transName, $agent_posts, 60 * $cacheTime);
  14.     endif;
  15.   // send back the result.
  16.     return $agent_posts;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement