$wp_query initiation?

User Rarst has a very famous answer where he lays out the load process. Looking at this graph whenever wp-blog-header.php gets loaded it calls function wp() which sets up many of WordPress globals like $post and $wp_query. ( Secondary Reference by User Gmazzap )

That’s the technical side of things but it looks like the core of your questions is creating your own custom archive pages. WordPress has a Template Hierarchy which allows you to create custom archives for things like Custom Post Types.

Another common way to modify the main query is to use a Hook in your functions.php file called pre_get_posts. This will let you modify the query object before WordPress actually pings to database to get the information which makes it very easy to modify The Loop with different settings. An example could look like this which would modify The Loop to show 20 posts instead of the default 10:

function wpse_265733( $query ) {

    // Don't run on admin
    if( $query->is_admin ) {
        return;
    }

    // Run only on the blog page
    if( is_home() ) {
        $query->set( 'posts_per_page', 20 );    // Set posts per page to 20.
    }

}
add_action( 'pre_get_posts', 'wpse_265733' );

Leave a Comment