wordpress – pagination in subpage

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:

Read More
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
        ));

Related posts

Leave a Reply

1 comment

  1. 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-

     <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            query_posts(array(
                'post_type'      => 'press_gallery',
                'paged'          => $paged,
                'posts_per_page' => 30
            ));
    
      $loop = new WP_Query($mypost);
      while ($loop->have_posts()) : $loop->the_post();?>
                <!--your code here-->
    
                       <?php endwhile;  wp_reset_query();  ?>   
    
       <!--at the end  just call this page navi function and you are done-->
    
     <?php  wp_pagenavi(array('query' => $loop));  ?>
    

    3)You are done 🙂