Possible Duplicate:
Pagination not working with custom loop
Apparently this is very popular issue. There are already bunch of people offering answers for this. But somehow after hours of searching I still can't get the solution. I hope someone can give me a clue here.
Currently I created a page for displaying all post from my custom post types. Here is my page template codes:
<?php
/*
Template Name:custom post type page
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type'=>array('car','bicycle'),
'posts_per_page'=> 20,
'page'=>$paged,
);
$the_query = new WP_Query( $args);
$num = $the_query->found_posts;
if($the_query){
if ($the_query->have_posts()) : echo $num;
while ($the_query->have_posts()) : $the_query->the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
endwhile;
next_posts_link( 'Next', $the_query->max_num_pages );
previous_posts_link('Previous', $the_query->max_num_pages );
else : $return_string = 'no result';
endif; wp_reset_query(); wp_reset_postdata();
}
?>
</div><!-- #content -->
</div><!-- #primary -->
The problem here is when I click on the Next
(or Previous
), the query result remains same. I noticed that the url have show the page number (page/2/
,or page/3/
..etc). And the found_posts() remains same on each page
, everything seem alright, only the content not showing the correct query object.
I also tried add 'max_num_pages'=>2
to the wp_query argument, but still not helping.
Anyone idea?