0

I have a custom post type called pizza with a custom taxonomy called genero.

mypage/pizza/peperoni/

When I click subsequent paginated page links (e.g. [2], [3], [next])

mypage/pizza/peperoni/page/2

The post is displayed correctly, but when I try to go to next-page [2], takes me to an 404 page

my loop

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 2; 
$args = array(
  'posts_per_page' => 2,
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'genero',
            'field' => 'slug',
            'terms' => 'peperoni',
             'paged' => $paged,
        )
    )
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();?>

<?php the_title(); ?>
<?php                       
    }
}
wp_pagenavi( array( 'query' => $query ) );
wp_reset_query();  // Restore global post data stomped by the_post().

?>
  • Why do you create a new query instead of using the default main query? This is likely the source of your problem. Whether or not a page exists is based on the results of the main query- the main query has no page 2. – Milo Apr 16 '17 at 22:51
  • 1
    what is if you move the 'paged' parameter into the line after the 'posts_per_page' parameter? – Michael Apr 16 '17 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.