I am displaying 2 posts in archive page with pagination. But my next page pagination link is redirecting to the home page instead of going to next page with containing next 2 posts.
The URL is showing like - / but it is redirecting to the index page.
function.php
function pagination_bar( $custom_query ) {
$total_pages = $custom_query->max_num_pages;
$big = 999999999; // need an unlikely integer
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
));
}
}
archive.php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'paged' => $paged,
'category_name' => 'works',
'posts_per_page' => 2
);
$wrk = new WP_Query($args);
while ($wrk->have_posts() ) {
$wrk->the_post();?>
<a href="<?php the_permalink() ?>">
<div class="inner_work">
<div class="work_arc_img">
<?php the_post_thumbnail(); ?>
</div>
<div class="work_card">
<p class="in_work_title"><?php the_title(); ?></p>
</div>
</div>
</a>
<?php } ?>
<nav class="pagination">
<?php pagination_bar( $wrk ); ?>
</nav>
<?php wp_reset_postdata();?>