Created
August 28, 2017 18:23
-
-
Save j3j5/7710b5fcab17e61b3a39178cba7d17b8 to your computer and use it in GitHub Desktop.
Log all SQL queries made from Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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