Executing view twice with different filters returns same results Here's my simple scenario :


Execute view with exposed filter (min &amp; 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-&gt;set_display('default');

$date       = $view-&gt;get_item('default', 'filter', 'created');
$date['value']['min']   = date('Y-m-d', $date_from);
$date['value']['max']   = date('Y-m-d', $date_to);
$view-&gt;set_item('default', 'filter', 'created', $date);

$view-&gt;pre_execute();
$view-&gt;execute();
$results = $view-&gt;result;

$view-&gt;destroy();

// do logic here to determine if view needs to be queried a second time

$view           = views_get_view('my_view');
$view-&gt;set_display('default');

$date       = $view-&gt;get_item('default', 'filter', 'created');
$date['value']['min']   = date('Y-m-d', 0);
$date['value']['max']   = date('Y-m-d', $date_to);
$view-&gt;set_item('default', 'filter', 'created', $date);

$view-&gt;pre_execute();
$view-&gt;execute();
$results2 = $view-&gt;result;

$view-&gt;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.

[1] Clear views cache after node inserted in Drupal 7
The second argument to views_get_view is $reset:


  If TRUE, reset this entry in the load cache.


So second time around you just need to pass that:

$view = views_get_view('my_view');
$view-&gt;set_display('default');

...

$view = views_get_view('my_view', TRUE);


That will reset the static cache and the data will be fresh.