Display The Number of Database Queries In Wordpress

When you are preforming maintenance on a Wordpress blog one of things you need to check for is the speed of your Wordpress database. You need to make sure that the amount of queries is down to a minimum and that there isn't anything holding up the database. In Wordpress there is a couple of inbuilt functions that allow you to display the amount of SQL queries and the time it took them to run on any page. Using this display you can then see what affect different changes make to your Wordpress database. Some of the tips mentioned in 11 Steps To Speed Up Your WordPress Site talk about database optimisation and reducing database calls by caching. It is very useful to take note of how long a page takes to load before and after you make these changes to see what affect they have. Below a snippet you can use to display both the amount of queries and the time it took them to run. But you don't want these stats to be displayed to every visitor to your site so make sure you wrap them in a if statement to check if the user is logged in.


<?php 
if(is_user_logged_in()){
     echo get_num_queries().' queries in '. timer_stop(1) .' seconds.';
}
?>

UpChecker

Reliable uptime monitoring and instant alerts for any website downtime.

  • Uptime Monitoring
  • Performance Monitoring
  • SSL Certificate Alerts
  • Domain Monitoring
  • DNS Checker
  • XML Sitemap Monitoring