Home › Forums › Feature Requests › View Related Records › Reply To: View Related Records
Good question…. here’s how I might tackle it…
First… as we know…
We have a ‘Doctors’ CPT
… with a ‘Locations’ Relationship field.
This ‘Locations’ field may have a series of Location IDs (say: 5, 6, 7)
Now, we have the ‘Locations’ CPT
When looking at ‘Edit Locations’
… we could have a ‘Doctors’ Relationship field here.
In it… we could work this hook…
… to fetch all the Docs that are attached to that Location.
Now, as an alternative… if you just wanted to do this for ‘Display’ purposes, you can pre-populate another field with the doc data… just use some other field type other than Relationship… like the ‘Enhanced Message’ add-on that allows for PHP, or maybe some other built-in field type like textarea, and make it read-only. Example here for making it read-only.
But… it’s better probably to use a Relationship field to make for smarter editing. But we have to keep the data in synch on our own from the way I understand it. So… each time a change is made to the ‘Doctors’ Relationship field when editing ‘Locations’, you can write logic that loops through and updates the ‘Doctors’ records (i.e. adds a location or removes a location).
Now, I haven’t thought far enough ahead to point you how to do the last part, because I’m not sure you wanted to get this far down the rabbit hole 🙂 Let me know!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.