- Created a view block with "search terms" exposed field and "taxonomy term" exposed field.
The Default value for "taxonomy term" is "Any".
View works perfectly and filters based on taxonomy term and/or search Term.
Question: Is it possible to create "Argument" to pass the url to "Default Value" for Taxonomy Term Exposed filter ?
For example, when a url is visited with taxonomy term "A", the Default Value of the Exposed Filter will be "A" instead of "Any" so that users can search within "A" immediately, instead choosing "A" one more time.
This is a common use case and it will be great if there is a way to proceed.
Thanks
Comments
Comment #1
merlinofchaos commentedSorry, you cannot currently accomplish this with Views.
Comment #2
mattbk commentedI would also like this to be possible. Views is keeping arguments and using them, and passing them to filters would be better.
Comment #3
joostvdl commented+1
Comment #4
momper commented+1
Comment #5
mugginsoft.net commentedThis can be accomplished like so. Hardly elegant but it does seem to cut the mustard.
The contents of a CCK select list are used rather than a taxonomy term but the problem is much the same.
View configuration
View accepts a single argument derived from a CCK field select list widget.
Filter is exposed as a block.
Filter block also includes the same CCK field as referenced in the argument.
Issue is that when filtering the view using the argument the block filter selection does not match the argument.
In the snippet below 'field_make_value_many_to_one' is the name of the form select item that you want to match to your argument.
Comment #6
momper commentednice - where i have to put this snippet?
Comment #7
mugginsoft.net commentedYou will have to put it into a module, hence the mymodule_ prefix.
Read up a bit on Drupal module hooks if you are in doubt about this.
In essence hook_form_alter simply doles out form definitions to any modules that are interested.
Comment #8
momper commentedthanks a lot
momper
Comment #9
Marko B commented+
Comment #10
sbydrupal commentedsubscribe
Comment #11
socialnicheguru commentedsubscribing. this looks good. thanks for the tip.
Chris
Comment #12
davidjmcq commentedDo you mean that's it's logically impossible? or that there is no current mechanism?
It sounds like a useful feature to me.
Comment #13
samchok commentedI'm also interested in having a default value different from 'any'.
Comment #14
shriji commentedYes this can be done. I just did it....we have over 25000 mp3 files. I created a view with filters based on categories, year, month, and day.
My problem was that when the page is opened for the first time, it takes for ever to load all 25000 entries. I wanted to limit the result by providing the default year argument to latest year 2011. I tried this and worked...this is what I did...
After you expose the filter, you will notice 2 settings....
1) Operator: Is one of - It is already selected and you have to take action
2) Select terms from vocabulary [your vocabulary name]: -
In item 2 above, just select any value that you want to be a default filter, thats it. Save the view and try it. You will see that the page will be filter with value you selected.
I have 4 different filters, all of them are exposed. Now I can change the default value thru any of the filters any time.
I hope I was clear about it. Let me know if you have any questions.
Shriji
Comment #15
my-family commentedsubscribe
Comment #16
neurojavi commentedHi:
I'm posting a corrected version of hack #5 that works for Views 3 in D7. I've changed some logic to avoid warnings when there's no argument in the url and, the most important thing, I've change the hook definition to get form_state by reference. I don't know how someone could make it work without this change... I've added a check for the view name and display so this doesn't affect other exposed filters.
If you use this code you must include it in a module and change uppercase strings with your own (in my case MY_EXPOSED_FILTER_FIELD_NAME was field_section_tid)
Hope this helps some one...
Thanks to muggin for his initial code.
PD: Changing to D7 and Views 3
Comment #17
user654 commented.
Comment #18
sbydrupal commentedI have set the
- view name
- display name = Page
- filter field name = tid (tid is by default)
Placed the code to a module, with <?php (no end tag)
Doesn't seem to work for Drupal 7. Could you please provide more feedback on details ?
Thx
Comment #19
sbydrupal commentedMerlin, would you happen to have any input on #16 ? Thank you!
Comment #20
sbydrupal commentedBelow code does not seem to work for drupal 7:
- module name: exposedfilterdefault
- view name: test
- display: Page
- field: tid
Thanks for any feedback.
How do other folks solve this problem ?
Using default taxonomy term view for the purpose of automatically capture taxonomy terms from url and use "1" view
instead of setting additional views for each category term. In this particular case, natural extension is to have exposed filter
with search terms and taxonomy filter to set to default term to search the view. How do you solve this problem otherwise ????
Thank you!
----------------------------------
Comment #21
TravisJohnston commentedGetting back to D6, this isn't working for me.
I've created a module for this and implemented the code from #5, changed the field_make_value_many_to_one to suit my filter which is views-exposed-form-news-block-3 for one and I will need to add another for another filter which is views-exposed-form-events-block-1.
My goal is this.
I have a News and Events page that has two blocks, News and Events. They can both be sorted depending on the Organic Group they belong to, so if you want to see what going on, you can changed the exposed Organic Groups filter.
What I did then was made it so I can have 1 single exposed filter to change the both of them. This works great.
But I have been asked to make it so if someone actually goes to a group and goes to the groups News and Events page, the same view should automatically default to the group it is in, and also allow you to change the filter to view other groups. This is easy at first with giving the view an argument to check, but of course the filter is at that point useless because once you change the filter, it doesn't meet the requirements of the argument.
To make this a little easier, I made the main news and events page a different block set since that page just needs to be set to Any by default which it is. The groups News and Events pages are a different block that needs the functionality above.
Comment #22
drupal12user commentedMy solution to apply a default value to an exposed filter directly from URL:
1. I have in the URL the exposed filter value (as GET argument; e.g: I have an exposed filter on City, I go in the exposed filter in the View and click "More", you will see "Filter identifier", I put "city_filter"; then, in my URL I add "..?city_filter=something" - it can come from a menu option or a GET form etc)
2. I set Use AJAX=Yes in my View > Advanced
3. A PHP small quick fix in the "sites\all\modules\views\modules\taxonomy\views_handler_filter_term_node_tid.inc" file (because I'm using taxonomy terms): add at the end the VALUE_FORM() function the following:
This way, when the URL is called first time, the GET values are used by the exposed filters, and then if the user filters on a different value, then the POST ajax value is used (by default Views uses the GET value even if the POST one is also assigned).
Maybe this can be better integrated in the Views by somebody who works on the Views module.
Comment #23
Mark_ commented#22 works great!
Comment #24
rdeboerSee Views Filter Harmonizer for a more elegant solution to #22 in D7.
Comment #25
chris matthews commentedThe Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue