Home › Forums › Backend Issues (wp-admin) › Dynamically populating repeater fields with default values? › Reply To: Dynamically populating repeater fields with default values?
Sorry, I know this is a very later post but very badly need it, I have an options page using ACF
This is the structure (OPTIONS PAGE)
- specifications - group
-- specifications_repeater - repeater
--- specification_name - text
so on the options page I added 3 fields and save
Size
Range
Colour
Now I have another another custom fields set in pages
- specifications - repeater
-- specification_item - text (populate this fields based on the "specification_name" field on the options page)
-- specification_value - text
What I want and hoping that it populates whatever its in the options page, so it will populate automatically the fields ( Size, Colour & Range )
I have this code below but it only populates “Colour” on all its fields, I think its pulling the last data.
function my_acf_load_field($field) {
$field['default_value'] = array();
if( have_rows('specifications', 'option') ) {
while( have_rows('specifications', 'option') ) {
the_row();
if( have_rows('specifications_repeater', 'option') ) {
while( have_rows('specifications_repeater', 'option') ) {
the_row();
$value = get_sub_field('specification_name');
$field['default_value'] = $value;
}
}
}
}
//$field['default_value'] = uniqid();
return $field;
}
add_filter('acf/load_field/key=field_5e86e1166f98a', 'my_acf_load_field');
also field_5e86e1166f98a is the target field
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.