Pagination on template page for custom query redirecting to index.php
I'm building my first theme and have a template page page-blog with a custom wp_query. I've tried adding pagination to the query but so far the pagination redirects to the index page. As expected the url structure shows /blog/page/2.
What am I doing wrong here? Do I need to just create my own pagination method?
div class=blog-listings
?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' = 'blog',
'post_status' = 'publish',
'posts_per_page' = '2',
'paged' = $paged,
'orderby' = 'date',
);
$blog_loop = new WP_Query( $args );
if ($blog_loop-have_posts()) :
while ($blog_loop-have_posts()) : $blog_loop-the_post();
include('template-parts/content/content-single-blog.php');
endwhile;
$total_pages = $blog_loop-max_num_pages;
if ($total_pages 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' = get_pagenum_link(1) . '%_%',
'format' = '/page/%#%',
'current' = $current_page,
'total' = $total_pages,
'prev_text' = __('prev'),
'next_text' = __('next'),
));
}
wp_reset_postdata();
endif;
?
/div
Topic paged page-template wp-query pagination Wordpress
Category Web