Skip to content

Instantly share code, notes, and snippets.

@madalinignisca
Last active October 3, 2016 15:09
Show Gist options
  • Save madalinignisca/314418f5f4518c64ed51569a61f48a49 to your computer and use it in GitHub Desktop.
Save madalinignisca/314418f5f4518c64ed51569a61f48a49 to your computer and use it in GitHub Desktop.
Load correct number of items when using Views Load More
<?php
/**
* Implements hook_views_query_alter()
*/
function views_pager_mod_views_pre_execute(&$view) {
// some data to be used
$query_params = drupal_get_query_parameters();
// Load the amount of items the user was looking at previous on Listings
if ($view->name == 'listing' and isset($query_params['historypage'])) {
$query = $view->build_info['query'];
$limit = $view->query->limit + ($query_params['historypage'] * $view->query->limit);
$query->range(0, $limit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment