I am creating a page managing concert dates. I constructed a view with an exposed filter for selecting a year to display all concerts taking place in that year. The exposed filter (appearing as a drop-down box) is configured to default to the current year ("now").
The issue is: the drop-down box always contains the current year +-3, so at the moment this is 2005, 2006, ..., 2008, ..., 2011. Regardless of whether there actually are any concerts in any of these years.
I'd like the drop-down box to contain only years where there are concerts in. For example, if I defined concert nodes (i.e. nodes with date cck-field) for 2006, 2008 and 2013, I'd like the drop-down box to only contain these three values. Is there any place where I could configure this?
At the moment, concerts taking place in years later than 2011 can't be displayed by the exposed filter because it contains only year values up to 2011.
Thanks in advance for any hints on this.
Comments
Comment #1
melvix commentedHere's how I did it.
In template.php:
Replace THEME_NAME with your actual theme name.
If there's a better way to do this, I would love to know what it is.
Comment #2
origaman commentedThank you very much melvix for posting this code. Works perfectly for me. I hadn't stepped into the php programming thing yet and it looks quite cryptic to me... But it works ;-)
So thank you, you made my day :-)!
Still I think this functionality should be integrated into views since the exposed filter is quite useless right now without this hack. So I'm keeping this thread open and changed the Category to "feature request": there should be at least an option for exposed filters to only expose values which are meaningful (or, non-empty).
Comment #3
origaman commentedHm, I detected a bug in the code posted in comment #1. Normally, the exposed drop-down box contains a value "-Year" which, if selected, does something like "show all". It is still there and does the same thing with the code from comment #1 in template.php, but with a warning box appearing on top of the page content saying:
"An illegal choice has been detected. Please contact the site administrator."
How can I get rid of this warning? And, is there a possibility to rename the "-Year" option to something like "<all>"? This "-Year" value is completely meaningless for my site's visitors, as is the "Absolute value" title of the drop-down which I already got rid of by means of CSS.
I wouldn't go as far as saying exposed date filter usability "sucks", but I'm close ;-).
Comment #4
B00N commentedhi, you can do it like that:
Comment #5
karens commentedThere were a couple other issues about this and I already commented on them. I committed some changes to the code so the filter will pick up the year range you put in the filter settings (it looks like '-5:+10'.