I have three content types: A, B and C.

A refers to B
and B refers to C

Now with use of the search api module I search my content types and I want to only output C. But in the result I want to show under which items the C is put. So some kind of breadcrumb. A view row should look like:

Type: C

Title of node

Found in: A > B

I am able to output the title of B but for some reason I'am not able to get the title of A. I tried to work with relationships in view but the A reference is not shown even not when I add B as a relation. I tried adding the content types to my search index and tried adding them direct as field to my search index ( field_content_B:entity:field_content_A:entity:title ). But nothing works. Can someone help me with figuring out what goes wrong?

  • Field probably only contains an ID. You probably need to load the entity from it. – leymannx Jul 17 at 14:08
  • Is this possible via views? – Joost Jul 17 at 14:09
  • With field formatters, yes. – leymannx Jul 17 at 14:27

None of the relations information is stored in C, so when you have C views it can't show relations info out-of-box.

Usually the way to show the "Child" for a "Parent" node is by using the Contextual filter for the Entity Reference field with the "provide default value" and "Content ID from URL" options. In your case A is a child of B, and B is a child of C.

Then you can use the Custom text field to construct your text, you can use the Contextual arguments in that field, this will give you information about the "Child" of the node in view row.

Maybe you can work through that to get to the "Grandchild" info, I haven't tried it.

I'd suggest chaining the reverse Relationships, they are called something like "Content referenced from field_my_reference", first you add the one for the child, then add another Relationship for the grandchild, and make the second Relationship use the First one. That's how you get to correct nodes.

Add the fields for the B and A titles with using the correct Relationship for each. Thena again you can use the Custom text field to override how their output is worded. You can "Exclude from display" the fields you use in Custom text after you have it showing the way you want inside Custom text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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