2

Looking through the pagination functions available in WordPress, most seem to be associated with posts. paginate_links() seems to be the only function which will work with WP_User_Query. However, when I use that I get numbered pagination:

echo paginate_links( array(
    'base'      => get_pagenum_link( 1 ) . '%_%',
    'current'   => max( 1, get_query_var( 'paged' ) ),
    'format'    => 'page/%#%/',
    'prev_next' => true,
    'total'     => intval( $wp_user_query->total_users / $number ) + 1
) );

How can I output "Prev" and "Next" pagination links that work with WP_User_Query? Note, I don't want to output numbered links such as 1, 2, 3 and so on.

3

I'm not aware of any generic helper - all the post-related navigation functions seem to be tied into the global WP_Query instance. The only real useful function at your disposal is get_pagenum_link:

$paged = max( 1, get_query_var( 'paged' ) );

if ( $number * $paged < $wp_user_query->total_users ) {
    printf( '<a href="%s">Next</a>', get_pagenum_link( $paged + 1 ) ); 
}

if ( $paged > 1 ) {
    printf( '<a href="%s">Back</a>', get_pagenum_link( $paged - 1 ) ); 
}

Note the function returns escaped strings by default, so no need for esc_url.

  • Thanks for this. I had an idea there wasn't something already pre-made. – henrywright May 24 '17 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.