In wp-config.php add this line:
define('SAVEQUERIES', true);
In your topic, the functions.php file (or the plugin file, for that matter) you can use this:
add_action('shutdown', 'sql_logger'); function sql_logger() { global $wpdb; $log_file = fopen(ABSPATH.'/sql_log.txt', 'a'); fwrite($log_file, "//////////////////////////////////////////\n\n" . date("F j, Y, g:i:sa")."\n"); foreach($wpdb->queries as $q) { fwrite($log_file, $q[0] . " - ($q[1] s)" . "\n\n"); } fclose($log_file); }
Make sure that ABSPATH.'/sql_log.txt' written in PHP.
Hope this helps.
source share