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 know I can use get_num_queries() for the number of queries. However, how can I see what queries Wordpress actually makes? I've tried using $query but that didn't work.

share|improve this question
up vote 6 down vote accepted

See this codex page.

in wp-config.php:

define('SAVEQUERIES', true);

then in your template:

if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    echo "</pre>";

or without the above SAVEQUERIES, you can still see just the main query:

global $wp_query;
echo $wp_query->request;

or to see all of $wp_query:

    <?php print_r($wp_query); ?>
share|improve this answer
Thanks Milo, much appreciated! – FLX Aug 21 '11 at 23:13
This is useful and the results are shocking, I can't understand why Wordpress makes soooo many useless queries – JasonDavis Apr 21 '12 at 20:49

Milo's answer is right on. I would add that to save you some trouble, download the WordPress Debug Bar plugin. This plugin will add a little bar to the bottom of your front end pages and it will capture important debugging information, including queries made during the request. For it to work you need to make sure that the constants WP_DEBUG and SAVE_QUERIES are set to true in your wp-config.php file.

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.