WP_Query debug in ajax call to avoid 500

How do I debug

$loop = new WP_Query(array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1));

It’s in functions.php file and called using AJAX admin-ajax.php:

Read More
jQuery.ajax({
  url: '<?php echo admin_url('admin-ajax.php'); ?>',
  data: data,
  type: 'post',
  dataType: 'json',
  ...

Doing it like:

$loop = new WP_Query(array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1));
var_dump($loop);
exit();

… simply gives 500 internal error in response.

EDIT: The error is in Query due to posts_per_page => -1. I was able to see the dump after changing -1 to 1 by personal judgement. But I am still so curios to know how do I debug an incorrect query.

Any suggestions?

Related posts