Puneet Sharma
Puneet Sharma

Reputation: 21

How can I get referencing entity Id from referenced entity?

I have 3 content types A, B, C. B and C have entity reference fields that reference to A and B and with different machine names. I want to get the parent node ID from referenced node.

A is referenced to B B is referenced to C

Now if I am on A then I want to get B node id and if I am on B then I want to get C node id.

How can I achieve this programatically.

Upvotes: 2

Views: 1038

Answers (1)

firewaller
firewaller

Reputation: 426

You could do this with the Corresponding Entity References module, which can create a two-way reference when a single reference is set. That way it prevents having to search for the parent.

Otherwise, you can use Views, which can search for the parent via Relationships.

Upvotes: 0

Related Questions