ThisCalculator

Everyday

Query Monitor: Debug a WordPress Site Step by Step

Updated · Standard formula, shown below

Query Monitor is a developer-focused plugin that shows you exactly what your WordPress site is doing behind the scenes: every database query, HTTP request, enqueued script, PHP error, and hook call. This guide walks you through using it to find slow queries, plugin conflicts, and coding mistakes so you can fix performance and functionality issues faster. You’ll need admin access to your WordPress dashboard and, ideally, a staging site to avoid affecting live visitors while you debug.

What You’ll Need

  • WordPress admin credentials (user with plugin installation rights).
  • Access to your site’s front end (to trigger the pages you want to debug).
  • Basic understanding of PHP, MySQL, and browser developer tools (helpful but not required).
  • A staging environment is strongly recommended for testing changes.

Step-by-Step

  1. Install and activate Query Monitor. In your WordPress admin, go to Plugins → Add New, search for “Query Monitor,” install it, and activate. The plugin is free and maintained by John Blackbourn.
  2. Enable the admin bar display. After activation, Query Monitor adds a new item to the WordPress admin bar (usually at the top). By default, it shows a summary like “0.012s, 10 queries.” If you don’t see it, check that your theme or other plugins aren’t hiding the admin bar.
  3. Open the Query Monitor panel. Click the Query Monitor icon in the admin bar. A dropdown appears with sections: Overview, Queries, Hooks, PHP, HTTP, Scripts, Styles, and more. The Overview panel shows total page generation time, memory usage, and query count.
  4. Identify slow database queries. Go to the “Queries” panel. It lists every SQL query executed on the current page. Look for queries with high “Time” values (e.g., > 0.05s). Click on a query to see its full SQL and the calling code (file and line number). This tells you which plugin or theme function is responsible.
  5. Check for duplicate queries. In the Queries panel, look for identical SQL statements repeated many times. This is a common sign of missing object caching or inefficient loops. The “Duplicate” column highlights repeats.
  6. Analyze HTTP requests. The “HTTP” panel shows all external requests made by the site (e.g., to APIs, CDNs, or remote servers). Slow or failed requests here can cause page delays. Check each request’s time and status code.
  7. Inspect PHP errors and warnings. The “PHP” panel lists any notices, warnings, or fatal errors that occurred during the page load. These are often hidden on live sites but can break functionality. Click an error to see the stack trace and source file.
  8. Review enqueued scripts and styles. The “Scripts” and “Styles” panels show every CSS/JS file loaded on the page. Look for missing assets (404 errors) or scripts loaded on pages where they aren’t needed. This helps with render-blocking issues.
  9. Examine hooks and actions. The “Hooks” panel lists all actions and filters fired during the request, along with the functions attached to them. This is useful for finding code that runs too often or unexpectedly.
  10. Use Query Monitor on a specific page. Navigate to the page that’s slow or broken (e.g., a product page or a custom post type). The admin bar shows data for that page only. For logged-out users, you may need to test in an incognito window, but Query Monitor only shows for logged-in users with the right capability.
  11. Save a query log for comparison. If you need to compare before/after changes, use the “Query Monitor” → “Tools” screen (available in the admin menu) to log queries to a file or database. This helps track improvements.
  12. Deactivate plugins one by one. When you find a problematic query or error, note the source file. Then deactivate the suspected plugin and reload the page to see if the issue disappears. Re-enable it before moving to the next plugin.
  13. Apply fixes based on findings. Common fixes include: adding an index to a database table, enabling object caching, replacing a heavy plugin with a lighter alternative, or fixing a custom query to use WP_Query properly instead of raw SQL.

Common Mistakes

  • Checking the wrong page. Query Monitor shows data for the current page only. If you’re debugging a slow homepage, you must be on the homepage.
  • Ignoring the “Caller” column. The query itself isn’t always the problem; the code that runs it might be. Always check the caller to find the responsible plugin/theme.
  • Disabling Query Monitor on live sites. Leaving it active on a production site can expose sensitive information (like SQL queries) to anyone with admin access. Use it temporarily, then deactivate it.
  • Confusing query time with total time. A page can be slow due to PHP execution, network latency, or external requests, not just database queries. Check the Overview for a full breakdown.
  • Not checking for cached data. If you have a caching plugin, Query Monitor might show a cached page with no queries. Clear the cache before debugging.

Tips

  • Use the “Query Monitor” on a staging site. It’s safer to debug on a copy of your site where you can break things without affecting users.
  • Filter queries by type. In the Queries panel, you can filter by SELECT, INSERT, UPDATE, DELETE, etc. This helps isolate write operations that might cause locking.
  • Look for “slow” queries in the log. Query Monitor marks queries that take longer than 0.05s with a warning icon. Set your own threshold via the `qm/query_time` filter if needed.
  • Combine with browser DevTools. Use the Network tab in Chrome/Firefox to see server response times and waterfall charts. This complements Query Monitor’s backend data.
  • Check for “unexpected” hooks. If a page runs thousands of hooks, a plugin may be adding actions on every request. The Hooks panel shows the count per hook.
  • Keep Query Monitor updated. It’s actively maintained and may add new debugging features.

Troubleshooting

Query Monitor doesn’t appear in the admin bar. Ensure you’re logged in as an administrator. If you have a caching plugin, clear the cache. Also check that your theme isn’t removing the admin bar via `show_admin_bar(false)`. If the plugin is active but missing, try deactivating and reactivating it.

The panel is blank or shows “No data.” This can happen on AJAX requests or REST API calls. Query Monitor only tracks full page loads. For AJAX, you can use the “Query Monitor” → “AJAX” panel, but it requires the request to be made while logged in. For REST, check the “REST” panel.

Queries are not showing. If you use a persistent object cache (like Redis), Query Monitor may not capture all queries because they are cached. Disable the cache temporarily to see the raw queries.

You see a fatal error after activating Query Monitor. This is rare but can happen if your PHP version is too old. Check the plugin’s requirements (PHP 7.2+). If the site is broken, rename the plugin folder via FTP to deactivate it.

Query Monitor shows “0 queries” on a page. This usually means the page is served from a full-page cache. Clear the cache or use a URL with a query string like `?nocache=1` (if supported).

Frequently Asked Questions

Is Query Monitor safe to leave active on a production site?

It’s generally safe for administrators, but it exposes detailed debugging information (SQL queries, file paths) to anyone with admin access. It also adds a small overhead. Best practice is to use it on staging and deactivate it on live sites.

Can Query Monitor slow down my site?

Yes, it adds overhead because it logs every query and hook. The impact is usually small (a few milliseconds) but on high-traffic sites it can be noticeable. Use it only when debugging, not permanently.

How do I find which plugin is causing a slow query?

In the Queries panel, click on the query to see the “Caller” section. It shows the file and line number of the PHP code that executed the query. That file usually belongs to a specific plugin or theme.

What does “Duplicate” mean in the Queries panel?

It means the exact same SQL query was executed multiple times during the page load. This often indicates a missing object cache or a loop that runs a query inside a loop. Fixing duplicates can significantly speed up your site.

Does Query Monitor work with page builders like Elementor or WPBakery?

Yes, it works with any WordPress setup. It will show queries and hooks from those plugins as well. You can use it to identify if a page builder is running too many queries.

How do I see queries for logged-out users?

Query Monitor only shows data for logged-in users with the appropriate capability (usually administrators). To debug a logged-out experience, you can use a plugin like “Query Monitor” with a “User Switch” plugin, or use a separate tool like New Relic.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.