I remember in another theme I did, that the The Loop automatically looped for the number that was set in "Blog pages show at most" (Settings->Reading). The theme I am working on right now does not see to consider this number and loops for an infinite amount of time (and crashes of course). How do I make it to consider "Blog pages show at most" ?

3 Answers 3


The only reasonable guesses that come to my mind are that the theme (or a plugin):

  1. Modifies the main Query with a filter on pre_get_posts, so look for that filter.
  2. Just creates a new Loop with new WP_Query($args). You will have to dig through the template file to find out.
  3. Interrupts the post_per_page save process or alter the posts_per_page option in the database, so check the *_options table for the posts_per_page key (option_name) to rule that out.
  4. The Loop is not calling the_post. Without that, the Loop will never increment to the next post and the loop will run until the browser gives up.

I'd bet on #1, then #2, with #3 being a distant third. Without more information I can't give a solid answer.

Item #4 is a very viable option but the problem is not the query itself but the Loop.

  • Ok, so the main query of the home page never sets the post_per_page to the "Blog pages show at most" value by default? What is the default value to posts_per_page?
    – user25893
    Jul 7, 2013 at 21:27
  • 1
    get_option('posts_per_page') will get you the value saved in the database.
    – s_ha_dum
    Jul 7, 2013 at 21:30
  • But was is the default value of posts_per_page in the main query?
    – user25893
    Jul 7, 2013 at 21:32
  • 1
    That is the default in the main query, and I believe should be the default in any query unless specifically instructed otherwise.
    – s_ha_dum
    Jul 7, 2013 at 21:33
  • 1
    I told you the possibilities I can think of. Without analyzing the theme code I can't answer you with much detail.
    – s_ha_dum
    Jul 7, 2013 at 21:37

I just ran into this problem using pagination (not infinite loop). It seems that the "Blog pages show at most" controls how many total pages are available and does not realize how many posts are actually being shown....

For instance, if my category has 113 posts, and I show 10 results per page (using $args(posts-per-page = 10)) I should expect to have 11 pages... but since my "Blog pages show at most" is set to 20, I only have 6 pages available. This is what I figured out:

1                  POSTS #1-10              POSTS #1-10
2                  POSTS #11-20             POSTS #21-30
3                  POSTS #21-30             POSTS #61-70
4                  POSTS #31-40             POSTS #81-90
5                  POSTS #41-50             POSTS #101-113
6                  POSTS #51-60             404 Error
7                  POSTS #61-70             404 Error
8                  POSTS #71-80             404 Error
9                  POSTS #81-90             404 Error
10                 POSTS #91-100            404 Error
11                 POSTS #101-113           404 Error

As you can realize, I had a lot of posts missing from my list, and since my posts aren't numbered, it was difficult to figure out.

How to fix: Set your "Blog pages show at most" to a number LOWER than your lowest post-per-page. That way, Wordpress will allot enough pages for your query to complete... otherwise, you will get an error because the total pages expected by the plugin or your own code will exceed what Wordpress believes you should have.


If you just want to ignore the global setting for one custom query but leave it intact for others, you can just save the value of the option to a temp variable, update_option('posts_per_page', '') to your custom posts_per_page, and then at the end of your work reassign the original global value back to the option like so:

      $posts_per_page = 3;      
      $global_posts_per_page = get_option('posts_per_page');
      update_option('posts_per_page', strval($posts_per_page));

      // WP custom loop and work here

      update_option('posts_per_page', $global_posts_per_page);

It adds a couple extra writes to the database but I think you'll live.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.