Home › Forums › General Issues › Update fields after field group is set › Reply To: Update fields after field group is set
Hey John,
I made some adjustments based on your reply but the fields are still not populating. The field group is created with no fields, if you happen to have any other ideas that I could try.
In functions.php – This seems fine and is registering the group for the post type.
function test_update_acf_field_group() {
acf_add_local_field_group(array(
'key' => 'group_5',
'title' => 'Product Data',
'fields' => array(),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
));
}
add_action('init', 'test_update_acf_field_group');
This part is in a template file that I have assigned to a page and refresh to execute the code quickly for testing (which is initially why I thought maybe the template is loading at the wrong time to add the fields). I have echoed out the variables and copy/pasted the responses as comments so you can see the actual values coming out in the first run through that loop.
$count = 1;
foreach( $row as $r ){
echo $count; // shows 1
echo $r; // shows Part_Number
acf_add_local_field(array(
'key' => 'field_' . $count,
'label' => $r,
'name' => $r,
'type' => 'text',
'parent' => 'group_5'
));
$count++;
break;
}
Thanks again for your help!
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.