Instantly share code, notes, and snippets.

Embed
What would you like to do?
発行されたSQL文を表示させる
define('SAVEQUERIES', 1);
function koabase_disp_sql() {
global $wpdb;
echo '<table class="wp-list-table widefat fixed posts">';
echo '<thead><th>SQL</th><th>Time</th><th>Caller</th></thead>';
echo '<tbody>';
foreach ($wpdb->queries as $q) {
list ($query, $time, $caller) = $q;
echo sprintf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
$query, $time, str_replace(',', "<br>\n", $caller));
}
echo '</tbody>';
echo '</table>';
}
add_action('shutdown', 'koabase_disp_sql');
[wp-config.php]
define ('SAVEQUERIES', true);
[デバッグしたい箇所]
global $wpdb;
var_dump($wpdb->queries);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment