3

I use views-7.x-3.3 and field_collection-7.x-1.x-dev of 2012 Jun 28.

I have a very simple content type (person) with the following fields:

  • name: text
  • surname: text
  • mother language: term reference [en, fr, de]
  • portfolio: field collection of:
    • website language: term reference [en, fr, de]
    • url: link

I can create an exposed views filter on the mother language field just fine. The drop down appears and correctly filters the nodes as expected.

When I try to create a filter on the website language field of the portfolio field collection though, it fails to filter. No results are returned unless the dropdown value is set to "all".

Is it the case that field collection fields cannot participate in views filters? Is there a solution to that?

0

1 Answer 1

12
+50

Field collection items can perfectly participate as Views filters. The key is to use Views relationships. You can create a relationship for the portfolio field, and then in the filter specify to use that relationship. That will cause the filter to analyze the field collection's contents, as opposed to the host entity's.

For example, here I established a relationship to an image gallery collection, created a file id filter, and associated the filter with the collection. The fid filter is also exposed:

3
  • Thanks a lot for taking the time to explain this in detail. It worked.
    – cherouvim
    Aug 1, 2012 at 8:07
  • no problem @MohammadAlabed, always a pleasure. Jan 23, 2015 at 1:59
  • @amateurbarista Views by default creates separate row for each item in the field collection, say I have added 3 set of values to a node. When we add a relationship, the views displays it three times (every row contains all the field collection values) and the exposed filter works well. But when I set the delta to 1 in the view's relationships to display only one row for containing all the values of the field collection, the exposed filter does not work for all the values, instead it works for only the first value of the collection. How do I get over this ?
    – AkiShankar
    Feb 22, 2016 at 5:50

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