-1

I have some problems in making wp_pagenavi works. I have a custom post archive page in which I activated the function. Here's the code:

<?php 

// WP_Query arguments
$args = array(
    'post_type'              => array( 'connazionali' ),
    'nopaging'               => false,
    'paged'                  => '1',

);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
        the_title();
        the_content();
    }
wp_pagenavi( array( 'query' => $query ));
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();

?>

The pagination displays correctly but when I click on second page, the same three articles are displayed (even if the url /page/2 is correct). I noticed this problem only on archive page, while on category page it is working fine.

Ho can I solve the problem?

Thank you!

0

It always displays the first page because you tell it to: 'paged' => '1' :)

That said changing main query and especially pagination inside a template is inherently unreliable.

For proper customization of such you should always be adjusting main query before template is ever reached via appropriate hooks, typically pre_get_posts.

Your Answer

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

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