Title: next_posts_link
Published: April 25, 2014
Last modified: August 20, 2026

---

# next_posts_link( string $label = null, int $max_page )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#wp--skip-link--target)

Displays the next posts page link.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#parameters)󠁿

 `$label`stringoptional

Content for link text.

Default:`null`

`$max_page`intoptional

Max pages. Default 0.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#more-information)󠁿

This function prints a link to the next set of posts within the current query.
 
If you need the values for use in PHP, use [get_next_posts_link()](https://developer.wordpress.org/reference/functions/get_next_posts_link/).
Because post queries are usually sorted in reverse chronological order, [next_posts_link()](https://developer.wordpress.org/reference/functions/next_posts_link/)
usually points to older entries (toward the end of the set) and [previous_posts_link()](https://developer.wordpress.org/reference/functions/previous_posts_link/)
usually points to newer entries (toward the beginning of the set).

Parameter $max_pages is the limit the number of pages on which the link is displayed.
The default value “0” means “no limit”.

This function will not work (fail silently) if mysql.trace_mode is enabled in your
php.ini. If you can’t edit that file, try adding ini_set( 'mysql.trace_mode', 0 );
to your theme’s functions.php.

See also: [previous_posts_link()](https://codex.wordpress.org/Template_Tags/previous_posts_link)
and [next_post_link()](https://codex.wordpress.org/Template_Tags/next_post_link).

## 󠀁[Source](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#source)󠁿

    ```php
    function next_posts_link( $label = null, $max_page = 0 ) {
    	echo get_next_posts_link( $label, $max_page );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/link-template.php#L2611)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/link-template.php#L2611-L2613)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#related)󠁿

| Uses | Description | 
| [get_next_posts_link()](https://developer.wordpress.org/reference/functions/get_next_posts_link/)`wp-includes/link-template.php` |

Retrieves the next posts page link.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.71](https://developer.wordpress.org/reference/since/0.71/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#comment-content-1297)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/next_posts_link/#comment-1297)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-1297)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-1297)
 4.  **Usage when querying the loop with [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)**
 5.  Add the $max_pages parameter to the [next_posts_link()](https://developer.wordpress.org/reference/functions/next_posts_link/)
     function when querying the loop with [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/).
     To get the total amount of pages you can use the ‘max_num_pages’ property of the
     custom [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)
     object.
 6.      ```php
         // set the "paged" parameter (use 'page' if the query is on a static front page)
         $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
     
         // the query
         $the_query = new WP_Query( array(
         	'cat'   => 1,
         	'paged' => $paged
         );
     
         if ( $the_query->have_posts() ) :
         	// the loop
         	while ( $the_query->have_posts() ) : $the_query->the_post();
         		the_title();
     
         	endwhile;
     
         	// next_posts_link() usage with max_num_pages.
         	next_posts_link( __( 'Older Entries', 'textdomain' ), $the_query->max_num_pages );
         	previous_posts_link( __( 'Newer Entries', 'textdomain' ) );
     
         	// Clean up after the query and pagination.
         	wp_reset_postdata(); 
     
         else:
         	?>
         	<p><?php _e( 'Sorry, no posts matched your criteria.', 'textdomain' ) ); ?></p>
         	<?php
         endif;
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%3Freplytocom%3D1297%23feedback-editor-1297)
 8.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#comment-content-6641)
 9.    [Code Amp](https://profiles.wordpress.org/codeamp/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/next_posts_link/#comment-6641)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-6641)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-6641)
 11. **A warning when using with custom queries**
 12. This function `next_posts_link()` has a condition to run if `is_single()` is false.
 13. This is good to know when creating custom queries and adding pagination using 
     this function because where you place your custom query can change whether the
     pagination shows or not.
 14. What’s interesting is that:
      – `is_single()` doesn’t work on pages (or media) –`
     is_single()` does work on CPTs and posts
 15. So custom queries with this pagination placed on a single page **will work fine**,
     but add the same custom query + pagination to a single CPT or post, and **it will
     not show**.
 16.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%3Freplytocom%3D6641%23feedback-editor-6641)
 17.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#comment-content-1295)
 18.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/next_posts_link/#comment-1295)
 19. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-1295)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-1295)
 20. **Basic Example**
 21.     ```php
         <?php next_posts_link( 'Older Entries »', 0 ); ?>
         ```
     
 22.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%3Freplytocom%3D1295%23feedback-editor-1295)
 23.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/next_posts_link/?output_format=md#comment-content-1296)
 24.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/next_posts_link/#comment-1296)
 25. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-1296)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%23comment-1296)
 26. **Check if next link exists**
 27.     ```php
         if ( get_next_posts_link() ) :
         	next_posts_link( 'Older Entries »', 0 );
         endif;
         ```
     
 28.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F%3Freplytocom%3D1296%23feedback-editor-1296)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnext_posts_link%2F)
before being able to contribute a note or feedback.