I’ve run into this problem with PageNavi before. My solution is to hijack the $wp_query variable temporarily and then reassign it after closing the loop.
An example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args=array( 'post_type'=>'post', 'cat' => 6, 'posts_per_page' => 5, 'paged'=>$paged ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); /* PageNavi at Top */ if (function_exists('wp_pagenavi')){wp_pagenavi();} if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); /* DO STUFF IN THE LOOP */ endwhile; endif; /* PageNavi at Bottom */ if (function_exists('wp_pagenavi')){wp_pagenavi();} $wp_query = null; $wp_query = $temp; wp_reset_query(); ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.