[development] D6 Views 2 adding filter programmatically

Jeff Hartman lists at jeffhartman.com
Wed Jul 27 21:35:36 UTC 2011


I have a block view set up, but I need to add a filter that uses a value from the node.

Adding a dynamic value to the filter seems pretty straight forward:

$view = views_get_view('related_cities');
$display = 'block_1';
$view->set_display($display);
$filter_name = 'field_city_parent_id_value';
$filter = $view->get_item($display, 'filter', $filter_name);
$filter['value'] = 'my_new_search_value';
$view->set_item($display, 'filter', 'field_city_parent_id_value', $filter);


Problem is that I don't know where I should be running this code. Module or template? If I put it into a module, which function should it go in? I've tried it in hook_views_pre_render(), but I'm not sure how to get the results based on the new value.

Thoughts?



More information about the development mailing list