Support

Account

Home Forums ACF PRO Detect incoming and outgoing relations in bidirectional relationships Reply To: Detect incoming and outgoing relations in bidirectional relationships

  • Mr?

    I remember a discussion like this, unfortunately, I don’t remember the specifics of it or what I was thinking at the time I might have suggested it…..

    …. Did some more looking and I did find it. It was over 4 years ago and it was on the WP support forum for my plugin. Still can’t remember WTH I was thinking. Recording where the relationship was created would be incredibly difficult to record and maintain. Not to mention that I’d need to create some type of a usable function to allow you to get incoming vs outgoing relationships.

    One of the things about my plugin is that it is build for an extremely simple use case that requires exactly zero additional coding for that use case. This is the only reason that it still exists.

    How I would do this if I had to do this.

    I would build 2 relationship fields. I would not use a plugin. One of these fields would be editable, the other would not be editable and I would remove this field from the post editor using an acf/prepare_field filter. Or I would somehow disable this field using JavaScript or hide it using CSS.

    I would then code a 2 way relationship between these 2 fields. When saving a post I would update the hidden field based on the editable field. This way the field that is editable always refers to the “To” or “Outgoing” relationships and the hidden field always refers to the “From” or “Incoming” relationships.

    If I wanted to show both the outgoing and incoming relationships I would try to figure out how to make the incoming field read only or in some why not editable. I don’t know if that is actually possible so as a last resort I would create a message field and using an acf/prepare_field filter I would dynamically populate the message with a list of the incoming relationships with links to edit those posts.

    In this way I would have both incoming and outgoing relationships available in different fields and could use them as needed.