Question about views_get_view() and set_display()

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
ben.hamelin's picture

I'm hoping the Views experts out there can shed some light on the effect I'm noticing. I'll try to summarize as clearly and briefly as I can. Here goes:

THE PROBLEM: Needing to search the entire result set of a view that is paginated to determine if certain nodes were returned, then displaying information from those nodes on page 1 only, without affecting the remaining search results. The view has exposed filters for searching.

THE SOLUTION: Within my views "display" template file (views-view--search.tpl.php), I used the following code to obtain all results:

    $all_results_view = views_get_view('search');
$all_results_view->get_total_rows = true;
$all_results_view->set_display($view->current_display);
$all_results_view->set_items_per_page(0);
$all_results_view->execute();
$all_results = $all_results_view->result;

At this point, I am able to iterate over the results and output the necessary information on page 1.

WHY I'M CONFUSED AND WRITING THIS POST: I'm unclear as to how the $all_results_view maintains the arguments passed by the exposed filters. As I modify the search to produce varying result sets, the all_results_view adjusts accordingly! It seems as though the "set_display" method, which uses the current_display value also maintains the current filters. My problem is solved, but I'm curious as to how these are being maintained.

Any insight would be greatly appreciated! Thanks to all in advance!
bh

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week