Situation:
You add a filter twice (so you have instances of the same filter). Then you expose them.

Problem:
_views_view_build_filters() iterates over $view->filter then tries to match the correct exposed instance by looping over $view->exposed_filter and checking the condition: if ($filter['id'] == $expose['id']). It works if the filter has only one exposed instance. However, if there are more, the first exposed instance of the filter is going to match everytime.

Proposed solution:
Patch attached

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Status: Needs review » Reviewed & tested by the community

Ok, I must congratulate you on a 1 line fix that had simply never occurred to me that fixes a major limitation of Views. I was about to won't fix the issue and then I actually looked at the patch.

abu3abdalla’s picture

i will try it

Kripsy’s picture

Would this fix the problem of using a taxonomy as an argument and exposed filter?

trofimchouk’s picture

Status: Reviewed & tested by the community » Needs review

Patch needs fix.
In case of two optional filters (for the same field) the second one does not work.
So should change
!isset($view->used_filters['filter'. $count])
to
!isset($view->used_filters['op'. $count])

AmrMostafa’s picture

I cannot reproduce #4

Attached my test view export. Here is a summary:

  • Added 2 "Taxonomy: Term" filters and exposed both of them.
  • I selected "optional" for both and saved.
  • In the view page, I combined them successfully in a lot of patterns using Is One of, Is None of and the optionality "All".
trofimchouk’s picture

Oh.. sorry, I haven't mention that these filters are the CCK-Integer filters.

So to reproduce you should:
- have a Content type with CCK-Integer field
- create several nodes (with values of 2000, 3000 and 4000)
- create view with 2 filters for these fields (1st - "more", 2nd - "less") - So you get a kind of range filter.
- try to filter with "more than 2500" and "less than 3500"
- you should get all the nodes with field value more than 2500 but not less than 3500

Terran-2’s picture

I think this patch is meant to fix the problem I'm having, but after changing line 89 of views_query.inc from "if ($filter['id'] == $expose['id']) {" to "if ($filter['id'] == $expose['id'] && !isset($view->used_filters['filter'. $count])) {" as suggested by the original patch and to "if ($filter['id'] == $expose['id'] && !isset($view->used_filters['op'. $count])" as suggested by lancelot (#4) it doesn't seem to.

What I'm trying to do:
Filter my view using minimum and maximum values for a few fields (price, and home square footage). This works fine as long as I DON'T lock the operator (is greater than, etc.). If I lock the operator the view returns no results

What seems to be happening:
Views is taking the operator from the first instance of the field and using it in both filters. This doesn't break things when the operator can be changed manually, but when the operator is locked it breaks.

Should this patch fix this problem? What might I be doing wrong?

Thanks!

askibinski’s picture

I also applied the original patch, which did not work for 2 exposed filters on a cck integer field. (same usecase as lancelot at #6). I couldn't get any results back from great then (or equal) and smaller than or equal queries.
Then I also tried the modification at #4. Also no results.

Using Views 1.6.

esmerel’s picture

Status: Needs review » Closed (won't fix)

At this time, only security fixes will be made to the 5.x version of Views.