How to add new rows on ACF Repeater - Ybus
5643
post-template-default,single,single-post,postid-5643,single-format-standard,ajax_fade,page_not_loaded,,side_area_uncovered_from_content,qode-child-theme-ver-1.0.0,qode-theme-ver-10.0,wpb-js-composer js-comp-ver-4.12,vc_responsive

How to add new rows on ACF Repeater

How to add new rows on ACF Repeater

To get this task done, you will need to get the field keys. On the field group, click on the top: Screen Options and set the Field Keys to be displayed.


// Initialize the post ID to -1. This indicates no action has been taken.
$post_id = -1;
// Setup the author, slug, and title for the post
$author_id = 1;
$slug = $variable;
$title = $variable;
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the page ID so that we know the page was created successfully
$post_id = wp_insert_post(
array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => $author_id,
'post_name' => $slug,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'custom_post_type_name'
)
);
add_post_meta( $post_id, 'regular_custom field', $var);
add_post_meta( $post_id, 'regular_custom field2', $var2);
add_post_meta( $post_id, 'regular_custom field3', $var3);
add_post_meta($post_id, 'repeater_slug', $count);
//Create by Field Id to be queriable later
add_post_meta($post_id, 'field_5645ecd350bea', $count); // insert your own field key for the repeater
//check if there are products
if(count($sub_field_array_with_values) > 0) {
$i = 0;
// loop through the rows of data and insert information
while ( have_rows('field_5645ecd350bea', $post_id) ) : the_row();
//echo "updating fields";
//update field
update_sub_field('item_name', $sub_field_array_with_values[$i]);
$i++;
endwhile;
}
else {
echo "no sub fields to be added";
}
// Otherwise, we'll stop and set a flag
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if