Save all queries of WordPress to file

By.

min read

My profile

Share this:

Define the savequeries first

Then

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:s a")."\n");
    foreach( $wpdb->queries as $q ) {
        // fwrite( $log_file, $q[0] . " - ($q[1] s)" . "\n\n" );
        fwrite( $log_file, $q[0] . " - ($q[1] s)". " [Stack]: $q[2]" . "\n\n" );
        
        
    }
    fclose( $log_file );
}
Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *