WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 need to debug a problem with filters I have in place. they're affecting any url that includes a query; eg, http://my.domain.hk/?attachment=1. does anyone know in which function WP begins to work with this kind of url, one that includes a query?


share|improve this question
up vote 2 down vote accepted

Any url that doesn't point to a file/directory that actually exists is redirected (by .htaccess) to the index.php in the root of your WordPress install.

index.php is what actually loads WordPress and its settings etc. It then calls the function wp();, which is responsible for initialising WordPress' actually handling of the request.

wp() is little more than a wrapper for the wp-class class. In particular, the main() method:

function main($query_args = '') {
    do_action_ref_array('wp', array(&$this));

The parse_request() method turns the request (handling pretty permalinks, internal rewrites and extra arguments -i.e. interpreting ?attachment=1) into 'query_vars' (variables concerning the query). The query_posts() method then turns that into an actual WP_Query object (the globals $wp_the_query and $wp_query - which are initialised in wp-settings.php).

share|improve this answer
thank you for the detailed answer. the phrase 'internal rewrites' helped me. I found what I was looking for in redirect_canonical(). cheers. – Gregory May 1 '12 at 13:42

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.