First, let’s go through variables one by one:
-
$numpages
is set on eachsetup_postdata()
call. It becomes either1
or number of pages in multipage post. -
$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. -
$multipage
indicates if current post has multiple pages (in other words if$numpages
is larger than1
).
Where do they come from?
Mostly setup_postdata()
as you have discovered.
$multipage
get’s set to0
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.