Modify views filter

If you need to modify views filter from your module, e.g when changing settings to a content type, you maybe whant a CCK autocomplete filed to be filtered as well.

<?php
/**
 * Change views filter according to saved settings
 *
 * Thank heaven when you can manipulate views arguments in autocomplete CCK :-)
 *
 */
function _save_allowed_node_types($node_types) {

   
$set_types = array();
    foreach (
$node_types as $key => $value) {
       if (
$value != "0") {
          
$set_types[$key] = $value;
       }
    }
   
 
$get_view = db_query('SELECT vid FROM {views_view}
                        WHERE name LIKE "newsletter_articles" LIMIT 1'
);
 
 
$get_vid = db_fetch_array($get_view);
 
$views_vid = $get_vid['vid'];
 
   
$get_views_display = db_query('SELECT display_options FROM {views_display}
                                       WHERE vid = %d
                                          AND
                                          display_plugin = "default"
                                       LIMIT 1'
, $views_vid);
   
   
$views_display = db_fetch_array($get_views_display);
   
   
$views_display = unserialize(db_decode_blob($views_display['display_options']));

   
$views_display['filters']['type']['value'] = $set_types;
   
   
$views_display_serial = serialize($views_display);

   
$set_views_display = db_query('UPDATE views_display
                                       SET display_options= %b WHERE vid = %d
                                         AND
                                       display_plugin = "default"
                                       LIMIT 1'
,
                                      
$views_display_serial, $views_vid);
   
    if (
$set_views_display == TRUE) {
       
drupal_set_message(t('Modified views filters: types ( %types )',
                              array(
'%types' => implode(', ',$set_types))), 'status');
    }
   
    return
$set_views_display;
}
?>
Knowledge keywords: