0

I render the Views page on the user profile page to show the content this user created. Now the scenario changed and I have to render the content in which this user has been mentioned using Entity Reference fields. For just one field there is no problem, since I did it using Contextual Filter ... but when I'm trying to do so using multiple different fields (for different content types), then I do not get any results.

Is it possible to achieve this using UI or is it possible to put a custom query somewhere to get results and benefit from the Views fields?

Thank you all in advance!

2 Answers 2

0

If you think about writing this as a pure SQL query, what you are trying to do is have multiple WHERE conditions that are separated by OR operators.

Using OR operators with Conextual Filters is not possible out-of-the-box with Views. All Contextual Filters are added as AND filters.

There appears to be a module that adds this option, although I have not tested it. It doesn't have an official release, but appears to be in use by over 2000 sites, so might be worth a try: https://www.drupal.org/project/views_contextual_filters_or

Ultimately, however, this could be solved with a different data architecture. Is there a reason you have multiple different fields for referencing the user? Could these fields be combined into one base field, with instances on various content types? If so, then you can do it with a single Contextual Filter.

0

It can be done using views only, no need for a contextual filter.

Create a user view instead of a content view. Add the relationship content referencing user using the field entity reference field.

Add the content fields that you want, using the relationship for each of them.

Add the filter user = currently logged in user, using the relationship.

The result is all content of all content types, that reference the currently logged in user.

Your Answer

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

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