Advertisement
Guest User

Custom Query with Pagination

a guest
Jan 4th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. function filter_where( $where = '' ) {
  2.     // posts in the last 120 days
  3.     $where .= " AND post_date > '" . date('Y-m-d', strtotime('-120 days')) . "'";
  4.     return $where;
  5. }
  6. add_filter( 'posts_where', 'filter_where' );
  7.  
  8.  
  9. $wp_query->found_posts = count(query_posts(array('posts_per_page'=>-1,'cat'=>6) ) );
  10. $wp_query->max_num_pages = ceil($wp_query->found_posts / 9);
  11. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  12. $offset = ($paged-1) * 9;
  13. echo '$wp_query->found_posts=' . $wp_query->found_posts . '<br/>';
  14. echo '$wp_query->max_num_pages=' . $wp_query->max_num_pages . '<br/>';
  15. echo '$paged=' . $paged . '<br/>';
  16. echo '$offset=' . $offset . '<br/>';
  17. query_posts( array('paged'=> $paged ,'posts_per_page'=>9,'cat'=>6,'orderby'=>'rand','offset' => $offset, ) );
  18.  
  19. remove_filter( 'posts_where', 'filter_where' );
  20.  
  21. if ( have_posts() ) :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement