2

I have a content type with 2 Field Collections(both set for unlimited values), they are Author and Editor. Both field collections are using the same fields(first_name and last_name).

In a Views that I created has both field collections displayed. And I would like to exposed the First and Last Name, but they are not searchable without a relationship. Meaning I have to have 2 First Name and 2 Last Name filters exposed with different relationships.

How to make 1 first name filter exposed and searchable for both Author and Editor?

PS: I have done many other searchable Views page, but this is different(2 field collections with same fields).

3 Answers 3

2
+50

I agree with everything @Aaron said in his answer, however, if you don't want to restructure your view, you can search both fields with an exposed Global:Combine Fields Filter.

You'll need to have both fields listed in the Fields section (you can mark them as Exclude from Display if you want). Also, if you remove one of those fields while the filter is still in place, your view will throw an error.

Note: Remember, if you want to use Global:Combine Fields Filter for taxonomy terms, referenced nodes or field collections, you need to include a relationship to that entity and then add the search field to the field list.

Reference: How to filter by two fields using a single exposed filter in Views?

4
  • I'm using Views 7.x-3.3 and didn't see the "Global: Combine Fields Filter". Does it required additional module, setting, or plugin?
    – CocoSkin
    Aug 17, 2015 at 13:33
  • I believe my Views version is a bit too old
    – CocoSkin
    Aug 17, 2015 at 16:15
  • I believe Views 7.x-3.5 includes the filter - but you might as well just update to the latest version.
    – Isaac
    Aug 17, 2015 at 22:02
  • Great answer; didn't know that existed.
    – Aaron
    Aug 18, 2015 at 19:39
2

You need to make the base table for your View the Field Collection table rather than the Node (content) table. You'll need to add a filter to only show the type(s) of Field Collections you wish to query.

Now you'll be querying all Field Collections of the selected type(s), regardless of whether they're considered authors or editors. Simply add exposed filters to query on the first_name and last_name fields.

The real question is: what do you want actually displayed? If you only want data attached to the Field Collections displayed then that's easy enough. If you want to pull data from the host nodes beyond merely the NID then you're going to end up with 2 separate relationships to the nodes (one for each field) and you're probably not going to be able to get the UI you want out of that.

A much easier approach to all of this would be to put all of the "people" related to a node in a single Field Collection field and differentiate between Author and Editor by way of an additional "type" field in the Field Collection. You could then construct very straightforward views to query across all types of related people.

1
  • Ty for your respond. I'm displaying first name and last name grouped by author and editor. Beside that, I also need to displaying all other fields, including node title, body, and many others fields. It does require to have relationship for displaying title and body.
    – CocoSkin
    Aug 17, 2015 at 13:18
0

You could add a bit of javascript to maintain the 2nd set of filter fields in sync with the 1st. Then with some CSS you can hide the 2nd set of filter fields so the user doesn't see them.

The javascript would be something like the following:

var e = jQuery('#first-field-id');
e.on('keyup', function() { v = e.val(); jQuery('#second-field-id').val(v); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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