5.x-1.x views.module views_get_view($view_name)
6.x-3.x views.module views_get_view($name, $reset = FALSE)
7.x-3.x views.module views_get_view($name, $reset = FALSE)

Get a view from the database or from default views.

This function is just a static wrapper around views::load(). This function isn't called 'views_load()' primarily because it might get a view from the default views which aren't technically loaded from the database.


string $name: The name of the view.

bool $reset: If TRUE, reset this entry in the load cache.

Return value

view A reference to the $view object. Use $reset if you're sure you want a fresh one.

16 calls to views_get_view()
ViewsAnalyzeTest::testAnalyzeBasic in tests/views_analyze.test
Tests that analyze works in general.
ViewsExposedFormTest::testRenameResetButton in tests/views_exposed_form.test
Tests, whether and how the reset button can be renamed.
ViewsGlossaryTestCase::testGlossaryView in tests/views_glossary.test
Tests the default glossary view.
ViewsUIWizardJumpMenuTestCase::testJumpMenus in tests/views_ui.test
Tests the jump menu style plugin.
ViewsViewTest::testDelete in tests/views_view.test
Test deleting a view.

... See full list

1 string reference to 'views_get_view'
views_ui_add_form in includes/admin.inc
Form builder for the "add new view" page.


./views.module, line 1670
Primarily Drupal hooks and global API functions to manipulate views.


function views_get_view($name, $reset = FALSE) {
  if ($reset) {
    $cache =& drupal_static('ctools_export_load_object');
    if (isset($cache['views_view'][$name])) {
  $view = ctools_export_crud_load('views_view', $name);
  if ($view) {
    return $view


dvdroest’s picture

Since this method is considered to be "private" it comes with a manual. Please make sure to call $view->pre_execute() before calling $view->execute(); Failing to do so will end up with notices being thrown which in turn will avoid Drupal caching the page. This might also have an effect on external caching services such as Varnish.

For reference, here is how this method can be used to modify results before outputting it to the page:

  $view = views_get_view('view_name');
  // change the amount of items to show
  print $view->render();

More useful methods can be found by looking at the API docs: http://api.drupal.org/api/views/includes!view.inc/class/view/7

When the requirement is to just add a view (block) programmatically then please have a look at: http://api.drupal.org/api/views/views.module/function/views_embed_view/7

bribread22’s picture

Hi, I'm not too sure the function $view->pre_execute() is necessary for the later versions of Drupal because I got the White Screen of Death when I used that function. However, using all the other lines you provided worked great. Here's what my code looks like:

$view = views_get_view('my_view');
$objects = $view->result;
Shawn Conn’s picture

If you're looking for the D8 equivalent there's this static function: