Pagination redirects to home page

admin

Administrator
Staff member
Hi I'm using pagenavi plugin, the problem is that when i click on page 2 or other pages in pagination, it redirects to my homepage, pagination is also working on home page,(a static front page). However, the wordpress pagination on archieve pages is working fine. Can anybody help me in this please...

Code:
<ul class="product-items">
    <?php
$paged = (get_query_var('pages')) ? get_query_var('pages') : 1;

 $args = array(
    'post_type'=>'product',
   'posts_per_page' => 12,
   'paged' => $paged
); 

$product_query = new WP_Query($args);

while($product_query->have_posts()):$product_query->the_post(); 
 $id = get_the_ID();

?>


        <li>
                <a href="<?php the_permalink(); ?>">
                <span class="product-img"><?php echo get_the_post_thumbnail($id, array(300,150,true)) ?></span>
                <span class="product-detail"><?php $title=get_the_title(); echo $trimed=wp_trim_words($title,3) ?></span>
        </a>
            </li>
            <?php endwhile;   if(function_exists('wp_pagenavi')) { wp_pagenavi( array('query' => $product_query)); }

wp_reset_postdata(); wp_reset_query()?>
    </ul>