Execute a view in code and pass multiple arguments to an exposed filter? I am executing a View in code of a paragraph preprocess to allow dynamic listings. The user selects which content types they would like to show, and the View should return nodes of those types with the same taxonomy selected. The idea is they can add multiple paragraphs with different configuration, leveraging the same View just with different arguments.

In this view, Content Type is an exposed filter, set to allow multiple. Here is the code in the preprocess_paragraph hook:

$types = $paragraph-&gt;field_related_content_types-&gt;getValue();
$content_types = [];

foreach ($types as $type) {
  $content_types[] = $type['target_id'];
}

$view = Views::getView('related_content');
$view-&gt;setDisplay('related_content_display');
$view-&gt;setArguments(['type' =&gt; $content_types]);
$view-&gt;setExposedInput(['type' =&gt; $content_types]);
$view-&gt;preExecute();
$view-&gt;execute();

if (count($view-&gt;result)) {
  $variables['results'] = $view-&gt;buildRenderable('related_content_display', ['type' =&gt; $content_types]);
}


'type' is the filter name in the View. If I change it to only allow one value and pass it as a string, it works. So it seems like a syntax issue, but I cannot figure it out.

The method seems to indicate that this is possible:

  /**
   * Sets the arguments for the view.
   *
   * @param array $args
   *   The arguments passed to the view.
   */
  public function setArguments(array $args) {
    // The array keys of the arguments will be incorrect if set by
    // views_embed_view() or \Drupal\views\ViewExecutable:preview().
    $this-&gt;args = array_values($args);
  }
It looks like you're you doing an exposed filter and contextual filter for the type. As setArguments is for contextual filters and setExposedInput for exposed filters. If you've only got the exposed filter for type you should be able to remove setArguments and the 2nd argument on buildRenderable (which you dont need if you're doing setArguments) 

I've got something very similar with an exposed type filter and just pass it an array to setExposedInput  and it seems to works

$view-&gt;setExposedInput(['type' =&gt; ['news','page']]);