So I want to create a view filter programatically using hook_update in the .install file. I feel like I have it going, but the changes will not show up in the UI. Here is what I am doing, and the results:
This view already contains 2 filters. I used this code to view those filters:
$filters = $view->display_handler->get_option('filters');
var_dump($filters);
and it was clear that they were there. Then I went into the UI and created the new filter using the GUI tools there. Then I ran the above code again, and it showed me all 3 filters (the 2 previous ones, plus my new one). So far so good.
So now I backtracked the database to the initial state, so I only had 2 filters again. Then inside my install file I ran this code:
$name = "soccer_scores";
$view_display = 'default';
$view = views_get_view($name);
$view->init_display($view_display);
$view->preview = TRUE;
$view->is_cacheable = FALSE;
$filters = $view->display_handler->get_option('filters');
$filters['field_is_livescore_value'] = array(
'id' => 'field_is_livescore_value',
'table' => 'field_data_field_is_livescore',
... a bunch of other array data
$view->pre_execute();
$output = $view->display_handler->preview();
$view->execute();
$view->post_execute();
var_dump($filters);
So after the install file runs, when that last var_dump runs, it prints out the $filters array and it looks exactly like when I created the new filter using the GUI. However, when I reload the admin area for that view, no new filter appears, it just shows the existing 2 filters, but not the new one.
So I feel there is some step I am missing to make the change "stick". I can find so few docs on this, can anyone help?