Home › Forums › Front-end Issues › Create Post if it doesn't exist in relationship field › Reply To: Create Post if it doesn't exist in relationship field
Hi @maxaud
If you want to do it via Ajax, you need to check how relationship field works, and it’s not an easy task to do as relationship field has a complex system.
What I suggest you is to use a repeater to add a dummy post form to create the new post type 2. When the users save the post type 1, you need to use the acf/save_post hook to loop through the posted data and create them. After that, you can update the relationship field on the post type 1 with the newly created post type 2.
You can also clear the posted data after that so the repeater form won’t looks ugly.
I hope this makes sense 🙂
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.