如何显示由Wordpress做出的所有数据库查询? [英] How to display all database queries made by Wordpress?

查看:271
本文介绍了如何显示由Wordpress做出的所有数据库查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用类似于此处介绍的方法,我可以看到在加载页面时在Wordpress中进行的查询的总数。

Using a method similar to the one described here, I can see the total number of queries being made in Wordpress when I load a page.

现在,我想显示在加载网页时进行的所有数据库查询。这将允许我看到我最大的资源猪是谁,而不必经过消除我的所有插件和主题脚本的过程。

Now I'd like to display all database queries that are being made when a page loads. This would allow me to see who my biggest resource hogs are, without having to go through the process of elimination of all my plugins and theme scripts.

显示Wordpress所有数据库查询的最佳方式是什么?

What would be the best way to display all database queries made by Wordpress?

推荐答案

如果您向配置文件中添加 define('SAVEQUERIES',true),那么您可以通过添加以下内容列出当前页面的所有查询您的主题。

If you add define('SAVEQUERIES', true) to your configuration file, you can then list all the queries made for the current page by adding the following to your theme.

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

有关详细信息,请参阅文档: http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis

See the documentation for more details: http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis

这篇关于如何显示由Wordpress做出的所有数据库查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆