how to get pagination link url?

If you check out the source, they’re both wrappers around *_posts(), which in turn are wrappers for get_*_posts_page_link() (where the wildcard indicates either next or previous).

For example, next_posts() will echo or return the escaped URL, depending on the first argument:

$escaped_url = next_posts( false /* Don't echo */ ); 
next_posts(); // Prints escaped URL

Otherwise you can get the raw URL with get_next_posts_page_link() and do with it as you wish:

 $raw_url = get_next_posts_page_link();

 wp_redirect( $raw_url );

 // or...
 echo esc_url( $raw_url );

Leave a Comment