I’ve got a request and I’m not sure it’s even possible. I’m building a new site for a client and trying to replicate the functionality of a form on their old site using ACF. Here’s the basic rundown of requirements:
• “Location” drop down needs to be populated by posts from a custom post type
• The Address fields need to get their info from the selection in “Location”
• And finally (and this is the tricky one), I’d like to be able to create a new “location” post from these fields if it isn’t already in the list (i.e. maybe select “New” from the location list, then fill out the data and hit the save button)
Here’s a screen grab of what they were doing before to help complete the picture:
Anyway I think I can figure out the first two requirements (well, at least the first one), but I have my doubts about the third. My apologies if this isn’t the proper place for this kind of question, but I appreciate any insights (even if it’s just a simple “yeah that’s not gonna happen”)!
I would use a select field for the location select and dynamically populate it from the CPT values. That would also let you have a “New Location” value and have conditional fields if they’re needed.
I have some examples of populating fields based on other fields with custom AJAX requests here https://github.com/Hube2/acf-dynamic-ajax-select-example. They are only basic examples.
For the last one, you could create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/ for this form. Test to see if the value is “New” and if it is then create the new location post based on the input and update the location field with the ID of the new post.
Here’s another variable I neglected to explain: I’m hoping to keep all this in the back end. So workflow is basically like this:
1) Create new post under CPT
2) Fill out lots of basic fields and a few conditionals
3) One of those conditional fields unlocks the option to add location details, which is where the fields in question pop up.
So from the post creation page of CPT1, I’d like to be able to pull data and/or create a new post under a different CPT. Does that make sense?
I’m sure there’s a distinct possibility that your suggestions cover me and this is all just gonna go over my head so I appreciate your patience and assistance!
Ultimately we can make it work without that post creation step, but it sure would be nice!
If you want to be able to create everything about another post for the relationship then I would suggest this instead https://wordpress.org/plugins/quick-and-easy-post-creation-for-acf-relationship-fields/
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.