Faster, Higher, Stronger
更快,更高,更强

how to see sql queried by wordpress when opening a page

For learning purpose, it’s meaningful to looking at sql sentences queried by WordPress. But how to do this? Here is the answer.

First, edit the wp-config.php file, just add one line of code as below:

define('SAVEQUERIES', true);

Then, find the common footer.php file of your WordPress theme, add the following code before the ending </body> html tag (attention: here we only allow administrator to see these sql sentences, taking security into consideration):

<?php
if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    print_r($wpdb->queries);
    echo "</pre>";
}
?>

That’s all you need to do. You can now open a webpage and see corresponding sql sentences at the footer of the page. Thanks for reading!

赞(0) 打赏
未经允许不得转载:峰间的云 » how to see sql queried by wordpress when opening a page

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏