I'm trying to add filters dynamically in hook_views_pre_build.

<?php
      $options = array(
        'value' => $tids,
        'operator' => 'or',
        'group' => 0,
        'exposed' => FALSE,
        'type' => 'textfield',
        'limit' => TRUE,
        'vid' => $voc,
        'hierarchy' => 0,
        'relationship' => 'node',
        'reduce_duplicates' => 0,
      );
      $view->add_item($view->current_display, 'filter', 'term_node', 'tid', $options);
?>

But views doesn't use this filter. I guess its just a little step.

Comments

merlinofchaos’s picture

Status: Active » Fixed

Handlers are already instantiated at that point, so doing $view->add_item() won't work.

Either use hook_views_pre_view() or instantiate the handler after adding it and add directly to $view->filter[] array. The latter may actually be kind of difficult because handler instantiations are cached so the hook_views_pre_view() option may be better.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.