1

I have a view that select some nodes.

In views_post_execute I remove some results that cannot be directly removed by the query.

To do so, I have something like:

foreach($view->result as $key => $record) {
    if(my_test == true) {unset($view->result[$key]);}
}

To have this working, I had to remove the pager, otherwise $view->result contained only the first group of results.

After that foreach, I have the correct $view->result and I would like to display the results using a pager.

I tried with:

$view->set_items_per_page('25');
$view->init_pager();

but it doesn't work.

Any idea? thank you!

  • As a potential workaround, could you perhaps remove the results by manipulating the query pre_execute instead? – Letharion Oct 24 '14 at 8:48
  • no, unfortunately I can't do that. The query must be executed because I need the results to decide to keep or not a result. – lorenzo Oct 24 '14 at 12:17
  • 1
    What are you checking to keep result or not? You should be able to do it either via views itself or hook_views_query_alter. – 2pha Oct 24 '14 at 13:03
  • It's quite complicated to explain. The simplest case is: if a particular value is passed in $_GET (note that this is not an exposed filter, but added in the template manually), then I have to remove all results with more than three taxonomy terms. This is the simplest case. I can do that using views php, but then the pager doesn't work again. Also if you can do that through sql, it is not good because my database is huge and very complicated queries take too much time to be executed. Much better is to filter the results through PHP. – lorenzo Oct 25 '14 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.