Manually printing a Drupal view with PHP

In order to manually print a view you can run the following code:


There are some cases where you may want to alter the view before it is transformed into HTML. You can achieve that with the following code.

    //Get the view and push it to its pre-execution state
    $my_view = views_get_view('my_view_machine_name');
    //Do whatever you want to alter the view object now
    //For example, pass arguments to it.
    $my_view->args[] = 1;
    //Execute to get results filled in
    //Then return the view as HTML