Drupal View result count incorrect with Search API

In Drupal 7, if you use Views in combination with a search index from Search API, and you try to use the Global: Result summary in the header or footer of the View, you may find that the total number of results matches the number of items on the page, not the total number of items in the search index.

To correct this issue, hook_views_pre_execute will make everything work as you would expect.

<?php
/**
 * Implements hook_views_pre_execute().
 */
function MY_MODULE_views_pre_execute(&$view) {
 
// Set the View to compute total rows.
 
if ($view->name === 'MACHINE_NAME_OF_YOUR_VIEW') {
   
$view->get_total_rows = TRUE;
  }
}
?>

As always, a cache flush will be required to register the new hook.