Drupal 8: views_query_alter - setLimit()
If you need change the limit of a views query dynamically it would seem obvious to use:
$query->setOffset($offset);
$query->setLimit($limit);
However, the pager overrides this.
To make this work use the following:
$view->setOffset($offset);
$view->getPager()->setItemsPerPage($limit);
Note these methods are on the $view
object and not the $query
object.