0

I have date field. In views I want to add the a date exposed filter.

This filter will only display year and we can select multiple years.

Just like this

enter image description here

I have checked the better exposed filter module, date view and I did not find any option to display them in checkboxes nor I find any option to select multiple dates like in the picture we can select multiple years.

With the date views and better exposed filter, I can display year only in select list.

Is it achievable? Any suggestion?

  • can you add date views link in your question? – berramou Sep 20 at 22:12
  • @berramou It is not live. I am working on my local. – Ahmad Sep 23 at 11:03
0

You can construct the Exposed Year filter yourself using the Grouped filters option:

  1. Add your Date field Filter and Expose it
  2. Select Grouped filters under Filter type to expose
  3. Tick Allow multiple selections
  4. Select Radios under Widget type
  5. Adjust the Label and Description if you need to
  6. In the items table change all Operators to Is between and configure each year like so:

     2019   Is between   2019-01-01
                         2020-01-01
    
     2018   Is between   2018-01-01
                         2019-01-01
    
     2017   Is between   2017-01-01
                         2018-01-01
    
     ...
    

    and so on for all the years. The times are assumed to be 00:00:00.

You don't have to use the Better exposed filters, they may interfere with the display of the grouped options.

BTW this issue may be relevant: Grouped exposed filter with "Allow multiple selections" ignores widget setting

  • So I have to enter the years one by one. So it means it will be static? – Ahmad Sep 23 at 10:18
  • Also in the group filter, the view does now allow me to select the date ranges. – Ahmad Sep 23 at 11:13
  • Yes, the grouped filter option is static, you have to add each option manually. If you want to have something automatic you should look into Contextual filter for Year of your field set up to show Summary. They will be displayed as links, and users will have to click on one to get results, you can't choose two at the same time. You can put the Summary as a separate Block above your main Views results to be able to see both those links and results right away. You can always use custom code to make it work exactly how you want. What do you mean "date ranges"? – prkos Sep 23 at 17:27
  • From date ranges I mean for example the Is between 2019-01-01 2020-01-01 – Ahmad Sep 24 at 3:41
  • It doesn't let you change to Is between? Can you add a screenshot to your question? – prkos Sep 24 at 12:09

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.