Home › Forums › Backend Issues (wp-admin) › Create Multiple Posts on Back End › Reply To: Create Multiple Posts on Back End
Hi @karks88
If you want to keep the “Daily News Briefs” post and maintain the relation with its subfield, this will make things a bit more complicated 🙂
Because this is an advanced situation, I’m afraid I can only guide to do it. I’m sorry about that.
To maintain the relationship, I suggest you add post object field type in the new post repeater. When you add new posts from the repeater, you don’t need to select the post object field as we will do it automatically in the acf/save_post
hook.
In the acf/save_post
hook, you need to get the index key when looping through the repeater field like this:
foreach( $values as $key => $value ) {
After that, we need to update the post object field in the repeater values like this:
// post it!
$new_post_id = wp_insert_post($new_post);
$values[$key]['post_object_field_name'] = $new_post_id;
And after the loop, we need to update the repeater with the update_field() function like this:
update_field( 'new_posts', $values, $post_id );
This will add the newly created posts to the correct repeater rows. With this setup, you can check if the post object field is set or not like this:
if( $value['post_object_field_name'] ) {
If it’s set, get the ID and update it. If not, just insert a new post.
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.