15

I've noticed that a few Wordpress blogs have query statistics present in their footer that simply state the number of queries and the total time required to process them for the particular page, reading something like:

23 queries. 0.448 seconds

I was wondering how this is accomplished. Is it through the use of a particular Wordpress plug-in or perhaps from using some particular php function in the page's code?

3 Answers 3

18

Try adding this to the bottom of the footer in your template:

<?php echo $wpdb->num_queries; ?> <?php _e('queries'); ?>. <?php timer_stop(1); ?> <?php _e('seconds'); ?>
1
  • or wp-admin/admin-footer.php if you want it to show in the backend admin panel.
    – Phil
    Sep 26, 2015 at 14:02
6

To explain pix0r's code:

1

wordpress has a easy solution now

There is a function called get_num_queries() and as specified in other answers timer_stop().

<?php echo get_num_queries(); _e(' queries'); ?> in <?php timer_stop(1); _e(' seconds'); ?></p>

get_num_queries() - returns the number of database queries during the WordPress execution and accepts no parameters

3
  • Is there a way to put this in the backend admin panel too?
    – Phil
    Sep 25, 2015 at 12:52
  • get_num_queries() function is a global function. The above snippet should work in backend admin panel (wp-admin area).
    – Manoj H L
    Sep 26, 2015 at 13:04
  • Thanks. The best place for this is at the end of wp-admin/admin-footer.php
    – Phil
    Sep 26, 2015 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.