I'm creating a real estate website, I've created several content types of content for realty (flat, house, office).
Then I've created a view with filtering of the results.

I'd like to remove some option from my exposed filter. Now I have:

Filter results by:
Type:
- Flat
- House
- Office
- Page
- Story

I need to remove two last options. Unfortunately you can't do that using Views UI, but we can easily do it using theming!

Just open template.php from your theme, and paste there the following code (but without the <?php and ?> tags):

// Replace "VIEWNAME", in the function's name, with
// the name of your view.
function theme_views_display_filters_VIEWNAME($view) {
  $form = drupal_retrieve_form("views_filters",$view); 
  unset($form["filter0"]["#options"]["page"]);
  unset($form["filter0"]["#options"]["story"]);
  /*
  Filters (that is, fields) on the form are given sequential ID:
  'filter0', 'filter1', 'filter2', ...

  Above we assumed the the filter select-box is the first on the
  form and hence has a 'filter0' ID. If your filter is not the
  first on the form, adapt the ID accordingly. You may wish to do:

  echo '<pre>';
  var_dump($form);
  echo '</pre>';

  and inspect the output to find out your filter's ID.
  */

  $result = drupal_process_form('views_filters', $form);
  $output = drupal_render_form('views_filters', $form);
  return $output;
}

Big thanks to merlinofchaos that helped me to solve this problem!

Comments

Jax’s picture

How does this work in drupal-6.x with views-2.x?

thomasgm’s picture

On drupal 6, on the views module, you use the filter option and select Node:type from the filter option list.