Query posts and cache the query


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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;

URL: http://www.mp2013.fr

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.