Advertisement
Guest User

random order

a guest
Dec 28th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. //Retrieve consistent random set of posts with pagination
  2. function mam_posts_query($query) {
  3.     global $mam_posts_query;
  4.     if ($mam_posts_query && strpos($query, 'ORDER BY RAND()') !== false) {
  5.        $query = str_replace('ORDER BY RAND()',$mam_posts_query,$query);
  6.     }
  7.     return $query;
  8. }
  9. add_filter('query','mam_posts_query');
  10. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  11. $seed = gregoriantojd(date('h'),date('m'),date('d'),date('Y'));
  12. global $mam_posts_query;
  13. $mam_posts_query = " ORDER BY rand($seed) "; // Turn on filter
  14. $args = array(    'caller_get_posts' => 1,  // Stickies will be repeated if this is not set
  15.     'orderby' => 'rand',      // This MUST be in the query - the filter checks for it    
  16.     'paged' => $paged );
  17. query_posts($args);
  18. $mam_posts_query = ''; // Turn off filter
  19.  
  20. //query_posts($query_string . '&orderby=rand');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement