WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After taking a look at global $max_page; and global $numpages; on category-archive pages (is_archive() || $GLOBALS['wp_query']->is_archive returning true), I see the following return values:

  • $numpages: 4
  • $max_page: 7

What's going on here?

Further Qs:

  1. Where do they come from? After looking into /wp-includes/query.php I found $numpages in setup_postdata(), but beeing called as global on top and later counts the pages by the array that get's exploded through the <!-- nextpage -->-array.
  2. $multipage get's set to 0 if the $post->post_content is already an array. Why is this in this case set to 0, as the array indicates that it should be multipaged? Plus: Where could the array come from? post_content saves as string...
  3. Why do I have $numpages on archive templates/pages as it is only meant to be set for paged content types?
share|improve this question
up vote 1 down vote accepted

First, let's go through variables one by one:

  1. $numpages is set on each setup_postdata() call. It becomes either 1 or number of pages in multipage post.

  2. $max_page doesn't seem to be global at all. I don't see it referenced as such in code and from quick test it is not getting set on archive page for me.

  3. $multipage indicates if current post has multiple pages (in other words if $numpages is larger than 1).

Where do they come from?

Mostly setup_postdata() as you have discovered.

$multipage get's set to 0 if the $post->post_content is already an array

It does not. It gets set to 0 if $post->post_content does not contain any <!--nextpage-->.

Why do I have $numpages on archive templates/pages as it is only meant to be set for paged content types?

Because any loop sets it (in setup_postdata() call) and it remains set. It's like calling something after the loop that was not reset - globals still hold whatever post that was looped through last.

share|improve this answer
Ah, yea. Haven't thought about the fact that globals won't get reseted to zero (why should it). And global $max_page was my own failure. I needed a query var to be global to make it accessible in some other class and therefore put $GLOBALS['wp_query']->max_num_pages into global $max_page. :) If you want, you can close it as "too localized". – kaiser Oct 11 '11 at 22:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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