Finding Query Count for a Certain Part in a WordPress Theme
Michael Castilla’s post on modifying individual posts in the loop got me to test the query count between the double loop and single loop with counter method. This is my way to count that query count.
Say the Magic Word
This is how you would display the (current) query count in your theme:
<?php echo get_num_queries(); ?>
This piece of code is usually found inside footer.php, right at the very end of the code to display the total queries needed to display that single page. The secret is that you can place it just about anywhere inside your theme, and it will obediently display the total of query so far.
Also, you can have more than one of these in one go, so you could place one before and one after a certain part of a theme:
<?php echo get_num_queries(); ?> The Loop here... <?php echo get_num_queries(); ?>
…and you will have the query count before the loop and after it. Subtract the number and there you go, you have the total of queries invoked for The Loop.
One Trackback
[…] Source:Playworkplay.com (No Ratings Yet) Loading … 11 / May / 2008 Wordpress […]