Home › Forums › Front-end Issues › Using acf_form for multiple post_type › Reply To: Using acf_form for multiple post_type
Hi Enrico,
I think I see what you mean 🙂 So you’re creating a repeated field which has these fields (just an example):
When user’s save the field you would like to create posts based on the information the user has entered.
If this is correct you could use the acf/save_post action. This runs once the values for the repeater are saved. You can then retrieve them using the usual method, you could do something like this:
add_action( 'acf/save_post', 'my_custom_creator' ); function my_custom_creator( $post_id ) { if( have_rows('your_repeater') ): while ( have_rows('your_repeater') ) : the_row(); $postdata = array( 'post_title' => get_sub_field( 'title' ), 'post_content' => get_sub_field( 'content' ), 'post_type' => get_sub_field( 'post_type' ); ); $new_post_id = wp_insert_post( $postdata ); endwhile; } }
Do be careful though as this will create a new post each time you save the fields. You can either delete the post where the options are right after creating the new post, or you can save the ID’s of the newly created post and make sure they are not created, only updated if the options are saved again.
Hope I could help,
Daniel
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.