I can see a picture of the template hierarchy here, but where is the actual wordpress code which decides that it's a "category page" or an "archives page" or a "search page"?

1 Answer 1


wp-includes/template-loader.php is the file which is the template hierarchy. However, by the time that file executes, all the template decisions are already made since all that file does is check for boolean flags (defined in wp-includes/query.php function init_query_flags).

So all the heavy-lifting and interesting code happens before that at wp-settings.php line 225:

$wp_the_query = new WP_Query();

and it is definitely inside of the WP_Query class (starting with the constructor in wp-includes/query.php line 2998) where all the interesting logic happens.

Your Answer

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

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