如何显示Wordpress的所有数据库查询?

mat*_*ttz 15 database wordpress

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

现在,我想显示页面加载时正在进行的所有数据库查询.这样我就可以看到我最大的资源是谁,而无需完成我所有插件和主题脚本的删除过程.

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

Ric*_*d M 43

如果添加define('SAVEQUERIES', true)到配置文件中,则可以通过在主题中添加以下内容来列出为当前页面进行的所有查询.

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

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


jus*_*joe 5

或者你可以挂钩到posts_request.你可以把coe里面的函数.php等

add_filter('posts_request','debug_post_request'); // debugging sql query of a post

function debug_post_request($sql_text) {

   $GLOBALS['debugku'] = $sql_text; //intercept and store the sql<br/>
   return $sql_text; 

}
Run Code Online (Sandbox Code Playgroud)

在你的主题页脚中,你可以使用print_r之类的

print_r($GLOBALS['debugku']);
Run Code Online (Sandbox Code Playgroud)