Drupal - How do I print the SQL query of a view in front end?
You can enable on "Show the SQL query" and "Show other queries run during render during live preview" on "www.example.com/admin/structure/views/settings"
Hope it will help you.
The Devel module includes the webprofiler module; you have to enable that to see the query log.
Note that there's currently a bug in core in 8.1 that prevents it from being used.
While you could install webprofiler module, if you've already got a custom module, it might be quicker to do this:
/**
* Implements hook_views_post_execute().
*/
function MY_MODULE_views_post_execute(ViewExecutable $view) {
if ($view->id() != 'MY_SPECIAL_VIEW') {
return;
}
dpq($view->query->query());
}