How to add paging to query

Rather than using next_posts_link and previous_posts_link, try paginate_links. It lets you specify the current page and total page count.

For example:

echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('«'),
    'next_text' => __('»'),
    'total' => ceil($total / $items_per_page),
    'current' => $page
));

Leave a Comment