I'm getting a page not found when I click on page 2 using wp-pagenavi. This is my code, is there anything obvious there that's wrong?

                <div class="news-content-inner">
                    <?php $portfolioloop = new WP_Query( array( 'paged' => get_query_var('paged'), 'post_type' => 'news', 'posts_per_page' => 4 ) ); ?>
                    <?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?>
                    <div class="news-item" onclick="location.href='<?php echo the_permalink(); ?>'">
                        <h2><a href="<?php echo the_permalink(); ?>"><?php echo the_time('d.m.Y'); ?> / <?php echo the_title(); ?></a></h2>
                        <p class="news-page">
                            <?php if (get_field('description') != "") { ?>
                                <?php echo the_field('description'); ?>
                            <?php } else { 
                                $newscontent = get_the_content();
                                $newscontent_str = strip_tags($newscontent, '');
                                echo substr($newscontent_str,0,250) . "…";
                            } ?>    
                    <?php endwhile; // end of the loop. ?>

                    <p class="news-page" style="font-size:12px!IMPORTANT;"><?php echo wp_count_posts('news')->publish; ?> news items</p>
                    <?php if (function_exists('wp_pagenavi')) {
                    wp_pagenavi( array( 'query' => $portfolioloop ) ); } ?>


I tried the following:

I saved the permalinks again as that usually solves any problems like that but that didn't work so I set permalinks to default, saved, that worked for the pagination but now clicking on a post had a 404. So set it to post name then saved again and it was just back to normal where the pagination wasn't working.

  • What template is this in? – Chris_O May 16 '12 at 10:48
  • @Chris_O It's a page template I've made called news-overview.php – Rob May 16 '12 at 11:49

I solved this by changing the urls... seems such a stupid mistake now!

I had the same url for the page as the taxonomy and they were clashing. As soon as I renamed the page url the pagination worked.

  • this worked for me. the page was podcast and my post type is podcast as well. changed the page to /podcasts and it worked. – Loreto Gabawa Jr. Feb 8 '17 at 16:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.