立诚勿怠,格物致知
It's all about connecting the dots

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》
文章链接:https://www.orzzone.com/how-to-see-sql-queried-by-wordpress-when-opening-a-page.html
商业联系:yakima.public@gmail.com

本站大部分文章为原创或编译而来,对于本站版权文章,未经许可不得用于商业目的,非商业性转载请以链接形式标注原文出处。
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

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

非常感谢你的打赏,我们将继续给力提供更多优质内容!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册