0

I have a custom content type that has a date field. I have created a view with a exposed filter. The issue i have is that the exposed filter is in the form Y-M-D and i wan it to be just M-D. I have altered the exposed form, setup the #format to M-D and now the Y field is hidden. But it's still trying to validate it. and nothing shows up when you select values in the filter.

1 Answer 1

0

i have created a custom module.

function date_filter_form_alter(&$form, &$form_state, $form_id) {
  if($form['#id'] == 'views-exposed-form-birthdays-sliders-panel-pane-1') {
  $form['field_birthday_date_value']['value']['#date_format'] = 'm-d';
}
}

And query alter looks like:

function date_filter_views_query_alter(&$view, &$query) {
  if ($view->name == 'birthdays_sliders') {
    if (!empty($query->where[1]['conditions'][2]['field'])) {
    $query->where[1]['conditions'][2]['field'] = "DATE_FORMAT(field_data_field_birthday_date.field_birthday_date_value,
     '%m-%d') = :field_data_field_birthday_date_field_birthday_date_value";
}
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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