How do I programmatically change contextual filters? Basing on a blog post, I wrote the following code.

/**
 * Implements hook_views_pre_view().
 */
function mm_views_pre_view(ViewExecutable $view, $display_id, array &amp;$args) {
  if ($view-&gt;id() != 'product_listing' &amp;&amp; $display_id != 'page') {
    return;
  }

  $tid = reset($args);


  if (! $tid) {
    return;
  }

  $term = Term::load($tid);
  $terms = \Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')
    -&gt;loadTree($term-&gt;getVocabularyId(), $tid);

  foreach($terms as $child_term) {
    $args[] = $child_term-&gt;tid;
  }

}


I cleared the cache, but the code I wrote doesn't have any effect. The SQL query is not altered; only single taxonomy ID is returned. I have selected Allow multiple values for the filter.

What is wrong with the code? How can I fix it?
Args should be concatenated with , or +.

This work:

  $term = Term::load($tid);
  $terms = \Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')
    -&gt;loadTree($term-&gt;getVocabularyId(), $tid);

  foreach($terms as $child_term) {
    $args[0]  .= ',' . $child_term-&gt;tid;
  }