I have a child page with custom post query and i need to paginate them. The pagination query itself works, however, the links do not. Currently my page link is like this – /parent-page/child-page/
and the page links goes to /parent-page/child-page/page/2
, which returns 404. How can I make this work in this case?
The page link function:
function my_pagination() {
global $wp_query;
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
and a simple custom query in main page
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => 'press_gallery',
'paged' => $paged,
'posts_per_page' => 30
));
Just follow these steps and you will be done-
1)Install WP-PageNavi plugin and activate it.
2)Now your code should be like this-
3)You are done 🙂