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

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"?

share|improve this question

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.

share|improve this answer

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.