Here's my simple scenario :
- Execute view with exposed filter (min & max dates)
- If there are no results, execute again with min date = 0 to get all results
Unfortunately, the query static cache will execute the same query twice.
$view = views_get_view('my_view');
$view->set_display('default');
$date = $view->get_item('default', 'filter', 'created');
$date['value']['min'] = date('Y-m-d', $date_from);
$date['value']['max'] = date('Y-m-d', $date_to);
$view->set_item('default', 'filter', 'created', $date);
$view->pre_execute();
$view->execute();
$results = $view->result;
$view->destroy();
// do logic here to determine if view needs to be queried a second time
$view = views_get_view('my_view');
$view->set_display('default');
$date = $view->get_item('default', 'filter', 'created');
$date['value']['min'] = date('Y-m-d', 0);
$date['value']['max'] = date('Y-m-d', $date_to);
$view->set_item('default', 'filter', 'created', $date);
$view->pre_execute();
$view->execute();
$results2 = $view->result;
$view->destroy();
// $results and $results2 are identical
If I comment the first part of the code, the second query will work correctly and $results2 contains a lot more results.
I've tried answers from this question [1], but no luck.
The only solution I found is to clear the entire static cache with drupal_static_reset();
How to elegantly solve this problem? I believe clearing only the static cache for the queries will solve this, but I fail to find the good $name argument.