Creating filter seems to work but doesn't "stick"
To modify the value of a view programatically you don't need to actually render the view like you do with this part:

$view-&gt;pre_execute();
$output = $view-&gt;display_handler-&gt;preview();
$view-&gt;execute();
$view-&gt;post_execute();


They are only functions involved in rendering the view output.

The part you are missing is saving the view.

You are adding things to it but because you don't save it they don't end up in the database.

You will need to use the view::save() function like this:

// Load the view.
$view = views_get_view('VIEW_NAME');
// Modify the view here.
...
// Save the view.
$view-&gt;save();


[EDIT]

As for actually adding the filter. I recommend using the view::add_item() function instead of just manually adding to the view object because it does some extra work with the handler that isn't being done by your current code.

Some examples of using add_item() are https://drupal.stackexchange.com/a/134872/10729 and https://drupal.stackexchange.com/a/70649/10729