Update views result after unset() in views_pre_render In hook_views_pre_render(&amp;$view) I have a simple code:

foreach ($view -&gt; result as $key =&gt; &amp;$result) {
    if('some condition') {
        unset($view -&gt; result[$key]);
    }
    if('some condition') {
        unset($view -&gt; result[$key]);
    }
}


Above works OK. it unsets result row of the view. Now, in my view I am displaying 2 results per page. Currently have it outputs 10 node which means there are 5 pages. 

The problem is, as you might suspect that if, for example, 2 unset results happened to be on page number, say 2, of the view, this page is still displayed in the pager. So what I have now is 2 results on page number 1, no results on page number 2 and 2 results on page number 3.

Similarly, if only 1 result is unset, I have 2 results on page number 1, 1 result on page number 2 and 2 results on page number 3.

is there a way of letting the view know that it needs to update it's structure? There is a query_alter possible solution but I would like to avoid it if possible.

I do realise that this might not be the best way to unset results and I am open to suggestions, however i would like to keep the code in my custom module (not being fore to alter template.php).
You may want to look at doing this in Views' hook_views_post_execute():


  This hook is called right after the execute process. The query has been executed, but the pre_render() phase has not yet happened for handlers.


as the paging happens in the handler phase, and hook_views_pre_render()


  This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.


All about the various Views hooks is available here:  

https://api.drupal.org/api/views/views.api.php/group/views_hooks/7

Also, some interesting conversation about this process and potential alternate suggestions is available here in a drupal.org issue queue "update pager count after chaning results in hook_views_pre_render" as well.