Pagenavi with archive page

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!

Topic plugin-wp-pagenavi wp-query pagination Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.