3

I want to add an argument to a view. I want to set this argument programmatically (not by url).

The field i want to filter is not directly in the view query, because this is a field on a node reference, so I cannot use hook_views_query_alter.

How can i can add programmatically an argument to a view? I mean, which hook is better to do it?

9

You can use hook_views_pre_view and set arguments you want. For example

function hook_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name == 'your_view_name') {
     $view->set_arguments(array('arg1', 'arg2'));
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.