Friday, 9 August 2013

Wordpress: Pagination in custom loop not working

Wordpress: Pagination in custom loop not working

I have already searched several topics and questions regarding this
problem, but I haven´t found any answer that suits my code. The pagination
for my custom posts is displayed, but when I click in "Show next posts >>"
the same posts from the previous page are shown, even though the url shows
"?paged=2".
My code is the following:
<div class="podcast-entries">
<?php
$args = array( 'post_type' => 'strn5_podcasts',
'posts_per_page' => 3,
'paged' => (get_query_var('paged') ?
get_query_var('paged') : 1 );
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
?>
<div <?php post_class(); ?> >
<h4 class="podcast-title"><?php the_title(); ?></h4>
<div class="podcast-content">
<?php the_content(); ?>
</div>
<h6><?php the_time('F j, Y'); ?></h6>
<div class="post-separator col-lg-12"></div>
</div>
<?php endwhile; endif; ?>
<div class="navigation-links">
<div class="next-post">
<?php next_posts_link( '>> Siguiente Entrada' ); ?>
</div>
<div class="previous-post">
<?php previous_posts_link( 'Anterior Entrada >>'
); ?>
</div>
</div>
<?php $wp_query = null;
$wp_query = $temp;
wp_reset_query(); ?>
</div> <!-- .podcast-entries -->

No comments:

Post a Comment