Add a filter to my view before executing I have a view and I want to get it's results.

$nview = views_get_view('tasks');
$nview-&gt;set_display('page');
$nview-&gt;pre_execute();
$nview-&gt;execute();


If I have 'nid' filter added to my view, I can modify it and get my view filtered.

$nview = views_get_view('tasks');
$nview-&gt;set_display('page');
$nview-&gt;pre_execute();
$nview-&gt;display['page']-&gt;handler-&gt;handlers['filter']['nid']-&gt;value['value']=180;
$nview-&gt;display['page']-&gt;handler-&gt;handlers['filter']['nid']-&gt;operator='=';
$nview-&gt;execute();


But what do I need write to add a filter if no filter present in view settings of my view?

$nview = views_get_view('tasks');
$nview-&gt;set_display('page');
$nview-&gt;pre_execute();

//some code here

$nview-&gt;execute();


UPD: Unfortunately, I can't use hook_views_query_alter because I need to use my code in my custom function which accepts view's name as an argument.
My target is to alter any view which name passed as an argument to my custom function.
So I need to alter filter/query only if I need get view's result and the view executes from my function. But if the view executes from it's page or block it needs to be executed without altering.
Another way is to add the filter as an exposed filter in the view and then set it programmatically like this:

// Set created date range filter.
$item = $view-&gt;get_item($display_id, 'filter', 'created');
$item['value']['min'] = $settings['min'];
$item['value']['max'] = $settings['max'];
// Disable exposed filter in UI, for programmatic filter.
$item['exposed'] = FALSE;  
$view-&gt;set_item($display_id, 'filter', 'created', $item);


That should come before $view-&gt;pre_execute();

You can also add a completely new filter in a similar way, by building up a valid $item to use with $view-&gt;set_item.