0

I used the below code in hook_views_pre_view to add two exposed filter to a view, the first filter which provides available brand works perfectly but the second filter is not added at all, no error is logged though, any help on that?

  $available_brands = dpspec_get_available_brand_name($mid);

  $filter_options = array(
    'value' => $available_brands,
    'exposed' => TRUE,
    'reduce_duplicates' => TRUE,
    'type' => 'select',
    'required' => FALSE,
    'expose' => array(
      'operator_id' => 'field_brand_op',
      'label' => t('Brand'),
      'operator' => 'field_brand_op',
      'identifier' => 'sp_brand',
      'reduce' => TRUE,
      'vocabulary' => 'tags',
      'multiple' => TRUE,
    ),
  );
  $view->add_item($view->current_display, 'filter', 'field_data_field_brand', 'field_brand_tid', $filter_options);

  $available_colors = dpspec_get_available_color_names($mid);
  $options = array(
    'value' => $available_colors,
    'exposed' => TRUE,
    'reduce_duplicates' => TRUE,
    'type' => 'select',
    'required' => FALSE,
    'expose' => array(
      'operator_id' => 'field_color_op',
      'label' => t('color'),
      'operator' => 'field_color_op',
      'identifier' => 'sp_color',
      'reduce' => TRUE,
      'vocabulary' => 'tags',
      'multiple' => TRUE,
    ),
  );

  $view->add_item($view->current_display, 'filter', 'field_data_field_color', 'field_color_tid', $options);
0

OK the code is working fine, the only problem was that the color field was added to product, while views was set based on node, so when I added a relation to product, it started working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.