Set a view filter programmatically I have a view that includes a date field that only uses the year part.  I want provide a default filter value for this field based on the current date.  So far, I have this

function results_view_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
  if($view-&gt;name == 'results_view') {
    $year = date("Y");
    $view-&gt;display['default']-&gt;handler-&gt;options['title'] = $year . ' Results';
    $view-&gt;display['page']-&gt;handler-&gt;options['filters']['field_season_value']['value']['value'] =  = $year;
  }
}


This doesn't throw any errors but the filter view isn't filtered

I'm not sure what I'm doing wrong here, or if I'm even going down the right path.  The value I assigned above is based on the fact that when I hard code the year into my view, the view object looks like this

[field_season_value] =&gt; Array
(
        [id] =&gt; field_season_value
        [table] =&gt; field_data_field_season
        [field] =&gt; field_season_value
        [relationship] =&gt; none
        [group_type] =&gt; group
        [ui_name] =&gt; 
        [operator] =&gt; =
        [value] =&gt; Array
                (
                        [min] =&gt; 
                        [max] =&gt; 
                        [value] =&gt; 2013
                        [type] =&gt; date
                )


Just to clarify, the date field is based on a fiscal year that runs September through August. So if its May 2013, the date would need to be 2012. My example above is just a simplified version if what I'm going to need to do in the final version.
Set the default value to now using GUI. This should give you what you need without any code.

If you need to use fiscal years, either create own custom filter, one that will translate real date to fiscal year. Read manual and more detailed manual to see how to do it. Simply changing default value in date will not be enough, as user may inject date with more than a year set, making built-in filter not work the way you want it to. And then, well, then use now as default value.

You probably want to inherit from class views_handler_filter_date and override it's extra_options() method