Tutorial Example

WordPress Limit Number of Pages in Pagination – WordPress Tutorial

In wordpress, we may use function the_posts_pagination() to display pagination. For example:

while ( have_posts() ) : the_post();

    get_template_part( 'template-parts/content', 'search' );

endwhile;

echo '</div><!-- .posts-wrap -->';
the_posts_pagination();

You may see this kind of pagination:

There are 4 pages, however, if you want to limit the total page number to 2, how to do? In this tutorial, we will give you a tip.

How to limit number of pages in wordpress pagination?

We can add total parameter.

For example:

the_posts_pagination(array("total"=>2));

In this example, we will limit the total pages to 2. You will see: