0

I have two content types.

  1. Doctor
  2. Location

Doctor has two entity reference fields. Both reference Location nodes.

  1. Primary Location
  2. Secondary Location

I need to create a view that appears on a Location node and shows all Doctors that reference the Location node via the Primary Location or Secondary Location fields.

This has turned out to be incredibly difficult.

I've create a contextual filter for Content: Primary Location and set Provide default value to Content ID from URL. This successfully filters the view to Doctors that reference the Location via the Primary Location field.

I now create a contextual filter for Content: Secondary Location and set Provide default value to Content ID from URL. I now have no results.

I can then delete the Content: Primary Location contextual filter and this successfully filters the view to Doctors that reference the Location via the Secondary Location field.

It appears I can't have both at the same time. Thanks for any help!

1 Answer 1

0

Of course I solve this immediately after I post it after hours of trying. If you're in the same situation, it appears the only solution is to use https://www.drupal.org/project/views_contextual_filters_or .

Configure the view as described above. Then additionally, under Query settings, check Contextual filter OR.

The UI of this module leaves something to be desired but it works so long as all your contextual filters should relate to each other as OR.

The second missing piece was that I was testing this in the view UI using the preview. I was passing the NID of the Location as an argument. What I missed is that because I have two contextual filters I actually need to pass the NID twice like this: "2173/2173". When the view is actually used on the page, the NID is retrieved from the URL and the fact that there are two contextual filters becomes irrelevant.

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.