Posted By

Mat_ on 10/03/12


Tagged

wordpress query cache transient


Versions (?)

Query posts and cache the query


 / Published in: PHP
 

URL: http://www.mp2013.fr

Snippet to show a simple use of the transient API when querying posts.

  1. $bandeau_post = get_transient('top1_bandeau_post');
  2.  
  3.  
  4. if (!is_array($bandeau_post) || count($bandeau_post)==0) {
  5.  
  6. $args = array(
  7. 'posts_per_page' => 5
  8. );
  9. $bandeau_post = array();
  10. $bandeau_post = query_posts($args);
  11.  
  12. set_transient('top1_bandeau_post',$bandeau_post,60*60*$timeout);
  13. }
  14.  
  15. foreach($bandeau_post as $post) :
  16. setup_postdata($post);
  17.  
  18. // the display code
  19.  
  20. endforeach;

Report this snippet  

You need to login to post a comment.