These files are not loaded directly, but similar to regular template files, only after the WP
class is initialized. This class does the main query, which already can include the comments if the correct query variables are set.
The execution flow is a follows, starting in the main index.php
:
require('./wp-blog-header.php');
require_once( dirname(__FILE__) . '/wp-load.php' );
// Initialization of settings, plugins, theme
wp();
WP::main();
WP::init();
WP::parse_request();
// Parse `/feed/` and `/comments/feed/` and set the query variables
WP::send_headers();
WP::query_posts();
WP::build_query_string();
WP_Query::query();
WP_Query::init();
WP_Query::get_posts();
// This does the actual query
// `pre_get_posts` is the action you'll probably want to use
WP::handle_404();
WP::register_globals();
require_once( ABSPATH . WPINC . '/template-loader.php' );
if ( is_feed() ) {
do_feed();
// This calls the `do_feed_[feedtype]` action, e.g. rss2
do_feed_rss2( $for_comments );
if ( $for_comments )
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
else
load_template( ABSPATH . WPINC . '/feed-rss2.php' );
}