I have 2 separate views that return a set of results for each of my content types. The fields are different, but the filters are exactly the same - Sort by Location / Distance. This Distance / Proximity filter is exposed, and it is set to 'remember' the last entry. I followed the tutorial here http://drupal.org/node/359463 to be able to filter results by distance. It works great.
In views, to remember the last entry, Views uses sessions. But, each view has its own individual $_SESSION variable. That means what I set for one view does not carry over to the next, and even each view can have different values, which is not what I want. Here is a dump of the session after they have been set:
[views] => Array
(
[search_pages] => Array
(
[default] => Array
(
)
)
[baby_clothes_pages] => Array
(
[default] => Array
(
[distance] => Array
(
[postal_code] => 11211
[search_distance] => 100
[search_units] => mile
)
)
)
[baby_gear_pages] => Array
(
[default] => Array
(
[distance] => Array
(
[postal_code] => 22343
[search_distance] => 100
[search_units] => mile
)
)
)
)
What I would like to do is create a small module or snippet of code that will simply allow someone to type in their 5 digit zip code and then it update all the values across all my pages with this filter. If it is changed on any page, then it changes it for the rest of the pages as well. It also needs to work so that it affects the results on the next page load so that it correctly shows them filtered.
Here is a snippet of code I was experimenting with to try to set this value, but it's the wrong direction.
$all_views = views_get_all_views(); // get an array of all views in use on the site
foreach ($all_views['category_pages']->display as $key => $value) {
//check to see if the structure exists I am looking to modify
if(array_key_exists('postal_code', $all_views['category_pages']->display[$key]->display_options['filters']['distance']['value'])) {
//if so, set its value
$all_views['category_pages']->display[$key]->display_options['filters']['distance']['value']['postal_code'] = '28152';
//try setting the session instead
$_SESSION['views']['category_pages'][$key]['distance']['postal_code'] = '28152';
}
What's the correct direction? How do I get this value changed? Could it be done in the template.php file with preprocess function? Should I do it in a module, and if so, what do I need to alter?
Very lost at this point. Thanks for the direction!