Skip to content

Instantly share code, notes, and snippets.

@j3j5
Created August 28, 2017 18:23
Show Gist options
  • Save j3j5/7710b5fcab17e61b3a39178cba7d17b8 to your computer and use it in GitHub Desktop.
Save j3j5/7710b5fcab17e61b3a39178cba7d17b8 to your computer and use it in GitHub Desktop.
Log all SQL queries made from Wordpress
<?php
// Include this on your functions.php
function log_sql_queries($text_query){
/* //Uncomment me if you want a lot of info about where the sql query comes from and what action started it off
$traces = debug_backtrace();
foreach ($traces as $tobj => $trace) {
if($trace['function'] == 'do_action'){
$args = $trace['args'];
}
error_log("TRACE:$i:" . $trace['function'] . print_r($args,1));
$i++;
}
*/
error_log("INFO:SQL: " . $text_query);
return $text_query;
}
add_filter( 'posts_request', 'log_sql_queries', 500 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment