First, let’s go through variables one by one:
-
$numpagesis set on eachsetup_postdata()call. It becomes either1or number of pages in multipage post. -
$max_pagedoesn’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. -
$multipageindicates if current post has multiple pages (in other words if$numpagesis larger than1).
Where do they come from?
Mostly setup_postdata() as you have discovered.
$multipageget’s set to0if the$post->post_contentis already an array
It does not. It gets set to 0 if $post->post_content does not contain any <!--nextpage-->.
Why do I have
$numpageson 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.