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.
4 Answers
See this codex page.
in wp-config.php
:
define('SAVEQUERIES', true);
then in your template:
if (current_user_can('administrator')){
global $wpdb;
echo "<pre>";
print_r($wpdb->queries);
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
:
<pre>
<?php print_r($wp_query); ?>
</pre>