→ Debugging AJAX Queries

If you’re a developer, you may want to see FacetWP’s database queries. Most of FacetWP’s queries happen behind AJAX, but it’s now possible to see what’s going on behind the scenes. This works for FacetWP 1.2.2 and above.


Within wp-config.php, make sure the SAVEQUERIES constant is set to true.

define( 'SAVEQUERIES', true );

Make sure that SAVEQUERIES is only enabled when needed, since it’s a performance hit.

2. Inspect the AJAX request

With SAVEQUERIES enabled, FacetWP automatically returns a queries variable in the AJAX response. To view these queries, open Chrome’s developer toolbar, click on the Network tab, and refresh the page. Then, click on the “admin-ajax.php” request.


You’ll notice that the queries variable is an array of objects. Each array element has 3 properties:

  1. sql – the SQL query
  2. time – query execution time (seconds)
  3. stack – a stacktrace of how the query originated


3. What to look for

Pay special attention to the query time. Queries that take a long time to execute might need further analysis. Also, using the “stack” element, you can usually tell which plugin ran the query.

4. How to report an issue

When requesting support, please copy the entire AJAX response. You can get the raw response by clicking on the Network > Response tab.