Home › Forums › Backend Issues (wp-admin) › Pre-populate mulitiple Repeater rows
Hi there,
I’m using a repeater field with two sub fields: Caption (select) and Team Member (Taxonomy).
I’d like to pre-populate something like 8 rows with the Caption (select), so the editor doesnt have to add it manually each time.
I searched the forums and found this, but it doesnt work:
// Add pre-populated Repeater Fields
function my_acf_load_value($value, $post_id, $field) {
if ($value !== NULL) {
// if the value is exactly NULL it means
// the field has never been updated
// we don't want to change fields that have already been editied
return $value;
}
// set the new field value
$value = array(
// add a nested array for each row
array(
// add an array item for each sub field
'caption' => 'Production',
'team_member' => 'Test'
),
array(
// add an array item for each sub field
'caption' => 'Advertiser',
'team_member' => 'Test2'
)
);
return $value;
}
add_filter('acf/load_value/name=team', 'my_acf_load_value', 20, 3);
Any suggestions?
Two things you can try,
1) Lower the priority of your filter to < 10 add_filter('acf/load_value/name=team', 'my_acf_load_value', 1, 3);
2) Try using the field key instead of the field name add_filter('acf/load_value/jkey=field_XXXXXXX', 'my_acf_load_value', 20, 3);
Hi John,
Unfortunately both options did nothing to the fields.
Adding some echo text in between the function makes it seem like it’s not running at all? Any other way to test this?
Thanks!
If it’s not running at all then that’s another issue. Where is your code located? Place this at the top of the function to see if anything is output to know if the filter is running
var_dump($value);
Hi John,
I’ve tried this on a fresh install and it doesn’t work either.
if ($value !== NULL)
it at least gets to the $value array. If I don’t, it always seems to return NULL.array(2) { [0]=> array(2) { ["title"]=> string(10) "Production" ["member"]=> string(7) "Testone" } [1]=> array(2) { ["title"]=> string(6) "Artist" ["member"]=> string(7) "Testtwo" } }
Thank you for your efforts so far!
NULL
or it may be false
. Check this by placing var_dump($value);
at the top of your filter.Thanks John,
The empty $value returns bool(false)
.
I currently use the following which seems to work:
// Add pre-populated Repeater Fields
function my_acf_load_value($value, $post_id, $field) {
if ($value !== FALSE) {
return $value;
}
$value = array(
array(
'field_5e8317693aa96' => 'Production',
),
array(
'field_5e8317693aa96' => 'Director',
),
array(
'field_5e8317693aa96' => 'Author',
),
array(
'field_5e8317693aa96' => 'Artist',
),
array(
'field_5e8317693aa96' => 'Etc'
)
);
return $value;
}
add_filter('acf/load_value/name=team', 'my_acf_load_value', 1, 3);
Thanks a bunch!
The topic ‘Pre-populate mulitiple Repeater rows’ is closed to new replies.
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.