
Hi,
I would like to add rows to a repeater from collected datas using $_POST.
I have been able to publish my custom post type correctly using acf_form, however no rows get added to my repeater.
I am using the acf/save_post action to collect and save the new datas.
I have tried to look around but could not find the solution to my problem.
Thanks in advance if you can help me!
Here is the function I have used:
function ps_acf_save_post( $post_id ) {
// Get Fields
$fields = get_field_objects( $post_id );
// Prevent Infinite Looping
remove_action( 'acf/save_post', 'my_acf_save_post' );
// Grab Post Data from the Form
$post = array(
'ID' => $post_id,
'post_type' => 'leads',
'post_title' => 'Title Test',
'post_status' => 'publish'
);
// Grab Post Data from Dynamic Inputs
$fieldSets = (isset($_GET['line-item']) ? $_GET['line-item'] : null);
foreach((array)$fieldSets as $lineItem) {
// Repeater
$row = array(
'field_59104ba3d8b5a' => $_POST['row[1][category]'],
'field_59131578f9daf' => $_POST['row[1][product]'],
);
$row_id = add_row('field_59104b8fd8b59', $row, $post_id);
}
// Update the Post
wp_update_post( $post );
// Continue save action
add_action( 'acf/save_post', 'my_save_post' );
}
add_action( 'acf/save_post', 'ps_acf_save_post', 1, 1 );
Hi,
Solved my issue with this bit of code.
foreach($_POST['row'] as $rows)
{
$row = array(
'field_59131578f9daf' => $rows['category'],
'field_59104ba3d8b5a' => $rows['product'],
);
add_row('field_59104b8fd8b59', $row, $post_id);
}
<input type="hidden" name="row[<?php echo $i; ?>][category]" value="<?php echo $term_id; ?>" />
<input type="radio" name="row[<?php echo $i; ?>][product]" value="<?php echo get_the_ID(); ?>" <?php if ( get_the_ID() == $product_id ) echo 'checked="checked"'; ?> ><?php the_title(); ?>