My archive.php starts like this:

			get_header(); ?>
			<?php if( have_posts() ): ?>
				<div id="container" class="portfolio-wrapper">
				<?php while( have_posts() ): the_post(); ?>

I'm curious... where is the actual WP Query made? For example when I press on a Category or on an Archive link, I get to this page, but where's the actual select done?

I'm asking because I want to create a custom archive (using a shortcode with posts ids in it) and I want to see what is the best approach to do that :).