I am trying to implement pagination for category items listing archive.php page. But this does not work. Below is the code that I am using.
Custom Query:
$cat = single_cat_title("", false);
$cat_ID = get_cat_ID ($cat);
$args = array(
'posts_per_page' => '2',
'post_type' => 'mathematics',
'cat' => $cat_ID,
'paged' => get_query_var('paged',1)
);
$posts = new WP_Query($args);
Pagination code:
echo paginate_links(array(
'base' => '%_%',
'format' => '?paged=%#%',
'total' => $posts->max_num_pages,
));
When the page is loaded, it displays the pagination links but when I click on next it gives 404 error.
main page link: http://mk.local/category/mathematics/average/ when next is clicked : http://mk.local/category/mathematics/average/?paged=2
I have already tried updating permalinks